2表格上的数据网格.在第二个绑定不起作用 [英] 2 Data Grid on Form. In second binding doesn't work

查看:91
本文介绍了2表格上的数据网格.在第二个绑定不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单上发布了两个DataGrid,但是在第二个DataGrid绑定中不起作用.它们的属性ItemsSource显示相同的值.如果一个改变,第二个自动改变.如何使其正常工作?

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>

推荐答案

您已验证要绑定的属性确实存在于DataContext中.这是我第一次看到其名称使用英语以外的其他语言的属性...
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...


相关代码:
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");
    }
}

//我用于选择主题的组合框(themeSelector)

// 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");
    }

}


这篇关于2表格上的数据网格.在第二个绑定不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆