Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I dragged two Details (Gridview) from the Data Sources window unto my form and want them to display different rows from the same table.

I can't seem to be able to achieve this because any change I make to one reflects on the other one.


XML
<Window x:Class="MyApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MyApp" Height="579" Width="727" xmlns:my="clr-namespace:MyApp" Loaded="Window_Loaded">
    <Window.Resources>
        <my:MyAppDataSet x:Key="myAppDataSet" />
        <CollectionViewSource x:Key="membersViewSource" Source="{Binding Path=Members, Source={StaticResource myAppDataSet}}" />
    </Window.Resources>
    <Grid>

<Grid DataContext="{StaticResource membersViewSource}" HorizontalAlignment="Left" Margin="19,60,0,0" Name="grid1" VerticalAlignment="Top" Grid.ColumnSpan="2">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                           
                        </Grid.RowDefinitions>
                        <Label Content="ID:" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                        <TextBox Grid.Column="1" Grid.Row="0" Height="23" HorizontalAlignment="Left" Margin="3" Name="iDTextBox" Text="{Binding Path=ID, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" VerticalAlignment="Center" Width="120" />
                        <Label Content="First Name:" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                        <Label Content="{Binding Path=First Name}" Grid.Column="1" Grid.Row="1" Height="28" HorizontalAlignment="Left" Margin="3" Name="first_NameLabel" VerticalAlignment="Center" />
                       
                    </Grid>
                    <Grid DataContext="{StaticResource membersViewSource}" Grid.Column="1" HorizontalAlignment="Left" Margin="366,55,0,0" Name="grid2" VerticalAlignment="Top">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            
                        </Grid.RowDefinitions>
                        <Label Content="ID:" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                        <TextBox Grid.Column="1" Grid.Row="0" Height="23" HorizontalAlignment="Left" Margin="3" Name="iDTextBox1" Text="{Binding Path=ID, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" VerticalAlignment="Center" Width="120" />
                        <Label Content="First Name:" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                        <Label Content="{Binding Path=First Name}" Grid.Column="1" Grid.Row="1" Height="28" HorizontalAlignment="Left" Margin="3" Name="first_NameLabel1" VerticalAlignment="Center" />
                                            </Grid>
    </Grid>
</Window>


C#
private void Window_Loaded(object sender, RoutedEventArgs e)
       {

           MyApp.MyAppDataSet MyAppDataSet = ((MyApp.MyappDataSet)(this.FindResource("MyAppDataSet")));

           MyApp.MyAppDataSetTableAdapters.MembersTableAdapter myAppSetMembersTableAdapter = new MyApp.MyAppTableAdapters.MembersTableAdapter();
           myAppMembersTableAdapter.Fill(myAppataSet.Members);

           System.Windows.Data.CollectionViewSource membersViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("membersViewSource")));
           membersViewSource.View.MoveCurrentToFirst();




       }
Posted
Updated 7-May-13 5:11am
v2
Comments
Sergey Alexandrovich Kryukov 7-May-13 11:21am    
Just one note, not an answer: if you are "dragging" instead of programming, even on a XAML level, everything can happen. :-)
—SA

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