添加到数据表的新列未显示在datagridview中

时间:2018-08-10 12:23:59

标签: c# datagridview datatable tabcontrol

我创建了一个数据表,然后在位置0和1处手动添加了两个新列,并为其指定了默认值。当我遍历数据表时,它会正确打印所有值,并且似乎所有内容都在那里。但是当我通过绑定源将数据表传递给DataGridView时,它没有在datagridview中显示两个新列。知道我在做什么错了吗?

致谢

Amarino

DataTable lDT2 = Conn.ExecuteStoredProcedureValidation(lDT);

DataColumn newColumn1 = new DataColumn("TestName", typeof(string));
DataColumn newColumn2 = new DataColumn("SheetName", typeof(string));

newColumn1.DefaultValue = "test";
newColumn2.DefaultValue = "test2";

lDT2.Columns.Add(newColumn2);
lDT2.Columns.Add(newColumn1);

lDT2.Columns["TestName"].SetOrdinal(0);
lDT2.Columns["SheetName"].SetOrdinal(1);

DataGridView lDGV = new DataGridView();
lDGV.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing;
lDGV.RowHeadersVisible = false;

BindingSource BindingSource1 = new BindingSource(); //create new data binding source
BindingSource1.DataSource = lDT2;             //SetData source change to LDT2 
lDGV.DataSource = BindingSource1;
lDGV.RowHeadersVisible = true;

lDGV.Tag = page.Controls[0].Tag;
lDGV.AccessibleName = page.Controls[0].AccessibleName;

lFormV.tabControl_Val.TabPages[page.Name].Show();
lFormV.tabControl_Val.TabPages[page.Name].Controls.Add(lDGV);

0 个答案:

没有答案