本文介绍了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>
推荐答案
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表格上的数据网格.在第二个绑定不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!