我创建一个DataTable并将其绑定到DataGrid。我的数据源由一个表(FooTable)组成,它由一列(FooName)组成。添加行时在DataTable中重复列
下面的代码运行正常 - 除了每次添加新行时,都有一个重复的Column填充相同的数据,我不知道如何摆脱。请参阅下面的图片和代码。我只有一个FooName列和一个重复列出来。
/* Create a DataGrid dg1 */
DataGrid dg1 = new DataGrid();
DataGridTextColumn col = new DataGridTextColumn();
col = new DataGridTextColumn();
colA.Binding = new Binding("FooName");
colA.Header = "FooName";
dg1.Columns.Add(colA);
dataGrid1.Children.Add(dg1);
/* Create a DataTable and bind it to DataGrid */
SqlCeDataAdapter da = new SqlCeDataAdapter();
string sqlStr = @"SELECT * FROM FooTable";
da.SelectCommand = new SqlCeCommand(sqlStr, conn);
da.Fill(ds, "FooTable");
dt = ds.Tables["FooTable"];
DataRow newRow = dt.NewRow();
newRow["FooName"] = "Donkey";
dt.Rows.Add(newRow);
dg1.ItemsSource = ds.Tables[0].DefaultView;
哈哈,比我早34秒,好的一个:D – Damascus 2011-04-28 10:00:09
又一个快速绘制问题。 – 2011-04-28 10:16:23