带有多个Tableadapter的Datagridview,为每个视图查看不同的列

时间:2011-07-04 10:40:43

标签: c# winforms datagridview

我有一个带有多个表适配器的datagridview。每次点击dg都会在同一个控件上显示一个新表 如何在点击时显示不同的列? 我试过用

DataGridViewColumn newCol = new DataGridViewColumn();
DataGridViewCell cell = new DataGridViewTextBoxCell();
newCol.CellTemplate = cell;
newCol.HeaderText = "numOfTexts";
newCol.Name = "numOfTexts";
newCol.Visible = true;
dg1.Columns.Add(newCol);

但它不显示单元格内容,只显示列名称 感谢

1 个答案:

答案 0 :(得分:3)

您可以使用:

dg.AutoGenerateColumns = true;

请参阅MSDN

  

如果要自动创建列,则为true;否则,错误。默认值为true。

这正是显示表适配器的所有列所需的内容。

您可以隐藏不必要的列。

希望我帮助过......