Click here to Skip to main content
13,057,084 members (43,448 online)
Rate this:
Please Sign up or sign in to vote.
I have a tab-control with three tab items. each tab item has a datagrid placed on it.
and all these three datagrid's on their respective tab items is of Master-Detail-SubDetail form.

how to navigate from first tab item's to the second tab item' when a user selects a row on the master datagrid ? I have created a Model using ADO.Net entity framework to create this master-detail view.
Posted 4-Mar-13 10:47am
Updated 4-Mar-13 11:52am
Not clear. What do you mean by "navigate"? (Select, or what?) What tabs? Data grids have rows and columns, don't they?
ThePhantomUpvoter 4-Mar-13 17:40pm
I think that you need to reword your question. I do not believe you mean "navigate" here but something else.
BuBa1947 4-Mar-13 18:03pm
I am sorry for the confusing the question, it is how to move from one tab to another tab item wen a user selects a row on the datagrid.
ThePhantomUpvoter 4-Mar-13 18:09pm
Well.... okay.... have you tried setting the SelectedIndex property of your tab control to whatever index of the tab you want to navigate to?
BuBa1947 4-Mar-13 18:12pm
No, i haven't..

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I have an ObservableCollection which I would bind to the ItemsSource and I have a property type of Tag which I will bind to the SelectedValue. Whenever I want to change the selected tab, I just set the selected value. Here's my dirty code. I hope this will help you with your problem.
<Window x:class="WpfApplication9.MainWindow" 
        Title="MainWindow" Height="350" Width="525">
        <tabcontrol itemssource="{Binding TagCollection}" selectedvalue="{Binding SelectedTag}">
                    <textblock text="{Binding Name}" />                    
        <button content="Test" command="{Binding ClickCommand}" />

Here's the view model which I set to the data context of the view.
I created a click commant which will be triggered when you click the button. This will let you set the focus to TagCollection[1] (in a 0 based index it's the 2nd tab). Now the tricky part here is that you have to call raisepropertychange method on the setter. This will tell the view that someone set a new value for the SelectedTag and the view should update.
    public class TagVM: ViewModelBase
        ObservableCollection<tag> tagCollection;
        public TagVM()
            tagCollection = new ObservableCollection<tag>();
            tagCollection.Add(new Tag() { Name = "two", Priority = "2" });
            tagCollection.Add(new Tag() { Name = "another 2", Priority = "2" });
            tagCollection.Add(new Tag() { Name = "three", Priority = "3" });
            tagCollection.Add(new Tag() { Name = "one", Priority = "1" });
        private Tag selectedTag;
        public Tag SelectedTag
            get { return selectedTag; }
                selectedTag = value;
        public ObservableCollection<tag> TagCollection
            get { return tagCollection; }
                tagCollection = value;
        public ICommand ClickCommand
                return new RelayCommand(() => { SelectedTag = TagCollection[1]; }); 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170728.6 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100