Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I posted two DataGrid on a form, but in the 2nd DataGrid binding does not work. The properties ItemsSource they show the same values. If one change in the second changes automatically. How do I make it work properly?
<DataGrid Margin="8,72.04,8,-34" Name="AskDataGrid"
                           ItemsSource="{Binding Path=Вопросы}" SelectedCellsChanged="AskDataGrid_SelectedCellsChanged">
                        
</DataGrid>
                    
<DataGrid Margin="8,62,8,48.96"  Grid.Row="1" Name="AnswersDataGrid" AutoGenerateColumns="True" ItemsSource="{Binding Path=Ответы}" SelectionChanged="AnswersDataGrid_SelectionChanged">
</DataGrid>
Posted 5-Jan-12 21:14pm
Edited 5-Jan-12 21:46pm
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Did you validate that the properties that you want to bind to, realy exist in the DataContext. It's the first time I see properties which their names are in language other than English...
  Permalink  
Comments
Abbath1349 at 6-Jan-12 3:31am
   
yes
I did it. First DataGrid works correctly but second doesn't. But if i will write in C# IntemsSource=dataset.tables[name].defaultView. It works.
language isn't problem there.
Shmuel Zang at 6-Jan-12 7:12am
   
Can you post the relevant code of the class that is set as your DataContext (the definition of the property that you want to bind to) - use "Improve Question".
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

relevant code:
         private void themeSelector2_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             try
             {
                 if (myDataSet.Tables["Asks"]!=null)
                 myDataSet.Tables["Asks"].Clear();
                 DataRowView dw = (DataRowView)themeSelector2.SelectedValue;
                 string t = dw["Theme"].ToString();
                 if (t != null)
                 {
                     adapter.SelectCommand = adapterCommands.GetAsks(t);
                     adapter.Fill(myDataSet, "Asks");
                     AskDataGrid.DataContext = myDataSet;                     
                 }
 

             }
             catch
             {
                 //MessageBox.Show("Error");
             }
         }
 
// the Combobox (themeSelector) i use for select theme
         private void AskDataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
         {
           MessageBox.Show("Event");
             try
             {
                 if (myDataSet.Tables["Answers"] != null)
                     myDataSet.Tables["Answers"].Clear();
                 int i = AskDataGrid.SelectedIndex;
               DataRow dr = myDataSet.Tables["Asks"].Rows[i];
                 string s = dr[0].ToString();           
                     adapter.SelectCommand = adapterCommands.GetAnswers(s);
                     adapter.Fill(myDataSet, "Answers");
                     AnswersDataGrid.DataContext = myDataSet;
                   // AnswersDataGrid.ItemsSource = myDataSet.Tables["Answers"].DefaultView; // in this way all isworking
                    
 
             }
             catch
             {
                 //MessageBox.Show("Error");
             }
            
         }
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 215
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 159
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 6 Jan 2012
Copyright © CodeProject, 1999-2014
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