Click here to Skip to main content
12,078,259 members (47,332 online)
Rate this:
 
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 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".
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160212.1 | Last Updated 6 Jan 2012
Copyright © CodeProject, 1999-2016
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