Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 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?
XML
<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
Updated 5-Jan-12 20:46pm
v3

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...
 
Share this answer
 
Comments
Abbath1349 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 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".
relevant code:
C#
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
C#
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");
    }

}
 
Share this answer
 
v3

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