使用c#清除datagridview时,从datagridview中删除复选框列 [英] Remove check box column from datagridview when clear datagridview using c#

查看:616
本文介绍了使用c#清除datagridview时,从datagridview中删除复选框列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用复选框列动态创建了datagridview,一旦刷新了我的datagrid,它将删除除复选框列之外的所有数据,下面的代码用于在datagrid中添加复选框列



i have created datagridview dynamically with check box column,once i refresh my datagrid its removes all data except checkbox column,below code for adding checkbox column in datagrid

DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
dataGridView1.Columns.Add(chk);
chk.HeaderText = "Check Data";
chk.Name = "chk";
 int count = dataGridView1.Rows.Count;
 for (int i = 0; i < count; i++)
 {
     dataGridView1.Rows[i].Cells[12].Value = false;
 }



和以下用于清除我的数据网格的代码,如果我尝试在刷新后仍然在datagridview中添加新数据仍然存在旧复选框并且它继续添加一个复选框列。




and below code for clearing my datagrid,if i try to add new data in datagridview after refresh still old check box exists and it keeps adding one more checkbox column.

dataGridView1.Rows.Clear();
dataGridView1.Refresh();



任何建议???


any suggestion???

推荐答案

首先清除数据源,并清除绑定当您要清除时,数据源到网格视图。
Clear the data source first and , bind cleared data source to the grid view when you want to clear.


我尝试如下



i tried as follows

dataGridView1.Columns.RemoveAt(12);





i提到索引复选框和它的工作。



全部谢谢



i mentioned the index of checkbox and its worked.

Thanks All


这篇关于使用c#清除datagridview时,从datagridview中删除复选框列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆