Click here to Skip to main content
11,715,043 members (69,414 online)
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 20:14pm
Edited 5-Jan-12 20: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 Sergey Alexandrovich Kryukov 520
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 775
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 6 Jan 2012
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