Click here to Skip to main content
11,717,509 members (80,298 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ADO.NET WPF wpftoolkit
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
Edited 4-Mar-13 11:52am
v2
Comments
Sergey Alexandrovich Kryukov at 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
ThePhantomUpvoter at 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 at 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 at 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 at 4-Mar-13 18:12pm
   
No, i haven't..

1 solution

Rate this: bad
good
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" 
        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.
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]; });
        }
    }
}
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 689
1 OriginalGriff 255
2 F-ES Sitecore 210
3 Jochen Arndt 120
4 Maciej Los 120
0 Sergey Alexandrovich Kryukov 1,144
1 Maciej Los 509
2 OriginalGriff 505
3 Richard MacCutchan 440
4 CHill60 415


Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2015
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