Click here to Skip to main content
15,662,823 members
Please Sign up or sign in to vote.
1.00/5 (1 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.
Updated 4-Mar-13 11:52am
Sergey Alexandrovich Kryukov 4-Mar-13 17:39pm    
Not clear. What do you mean by "navigate"? (Select, or what?) What tabs? Data grids have rows and columns, don't they?
[no name] 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.
[no name] 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

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]; });
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900