我想在WinForm加载时在dataview中把原数据清除,显示自定义的列。可是显示出来的除了自定义列,原数据也都显示出来了。DataGridView.Columns.Clear();这个方法好象没起做用。但写在按钮里是好用的。 public Demo2()
{
InitializeComponent();
//读取数据到DataSet(代码略) dgvInfo.DataSource = ds.Tables[0];
System.Windows.Forms.DataGridViewTextBoxColumn ProductName = new DataGridViewTextBoxColumn();
ProductName.DataPropertyName = "productname";
ProductName.HeaderText = "商品名称";
ProductName.Name = "ProductName";
ProductName.Resizable = System.Windows.Forms.DataGridViewTriState.True;
dgvInfo.Columns.Clear();
clear()方法没有清除显示数据
dgvInfo.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { ProductName });
}
{
InitializeComponent();
//读取数据到DataSet(代码略) dgvInfo.DataSource = ds.Tables[0];
System.Windows.Forms.DataGridViewTextBoxColumn ProductName = new DataGridViewTextBoxColumn();
ProductName.DataPropertyName = "productname";
ProductName.HeaderText = "商品名称";
ProductName.Name = "ProductName";
ProductName.Resizable = System.Windows.Forms.DataGridViewTriState.True;
dgvInfo.Columns.Clear();
clear()方法没有清除显示数据
dgvInfo.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { ProductName });
}
解决方案 »
- DataView排序问题
- URLRewriter get参数丢失 谁遇到过
- 如果创建新的应用程序?
- c#中如何用数组接收10个数字
- C#如何传值给textbox(MySql数据库)
- PictureBox显示图片的问题
- 【通过压缩SOAP改善XML Web service性能 】这篇文章代码调通的朋友进来一下。
- 一个郁闷的问题:在office里面插入控件之后运行出现“The requested clipboard operation failed”
- DataSet问题求助
- 如果设置服务器 使 asp.net 不能运行 EXE ?
- 怎样实现合并AutoCAD的DWG文件或者DXF文件。高分相送。
- 新手提问,web页面如何显示PDF文件
dgvInfo.Columns.Clear();
在初始化的时候你看看还有没有其他地方有代码设置了列。
你加一个断点,
public Demo2()
{
InitializeComponent();
//读取数据到DataSet(代码略) dgvInfo.DataSource = ds.Tables[0];
System.Windows.Forms.DataGridViewTextBoxColumn ProductName = new DataGridViewTextBoxColumn();
ProductName.DataPropertyName = "productname";
ProductName.HeaderText = "商品名称";
ProductName.Name = "ProductName";
ProductName.Resizable = System.Windows.Forms.DataGridViewTriState.True;
dgvInfo.Columns.Clear(); //这时,列还没加载(加载事件还没执行) dgvInfo.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { ProductName });
}