Click here to Skip to main content
15,886,258 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.
Posted
Updated 4-Mar-13 11:52am
v2
Comments
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?
—SA
[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" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication9"
        Title="MainWindow" Height="350" Width="525">
    <stackpanel>
        <tabcontrol itemssource="{Binding TagCollection}" selectedvalue="{Binding SelectedTag}">
            <tabcontrol.itemtemplate>
                <datatemplate>                    
                    <textblock text="{Binding Name}" />                    
                </datatemplate>
            </tabcontrol.itemtemplate>
        </tabcontrol>
        <button content="Test" command="{Binding ClickCommand}" />
    </stackpanel>
</window>

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.
C#
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; }
        set
        {
            selectedTag = value;
            base.RaisePropertyChanged("SelectedTag");
        }
    }

    public ObservableCollection<tag> TagCollection
    {
        get { return tagCollection; }
        set
        {
            tagCollection = value;
            base.RaisePropertyChanged("TagCollection");
        }
    }

    public ICommand ClickCommand
    {
        get
        {
            return new RelayCommand(() => { SelectedTag = TagCollection[1]; });
        }
    }
}
 
Share this answer
 
v2

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