以简单的窗口形式向DataGridView添加复选框列 [英] add a checkbox column to a DataGridView in a simple window forms
本文介绍了以简单的窗口形式向DataGridView添加复选框列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我试图在一个简单的窗口表单应用程序中向DataGridView添加一个复选框列.
我正在使用ADO.NET从数据库中提取一些数据,放入数据表中,然后将datagridview数据源设置为该数据表.然后,我想添加一个复选框列作为第二列.到目前为止,我的这段代码似乎正常工作:
Hi
I am trying to add a checkbox column to a DataGridView in a simple window forms application.
I am pulling back some data from a database using ADO.NET, putting into a datatable, and then setting the datagridview datasource to the datatable. I then want to add a checkbox column as the second column. So far I have this code that seems to work:
推荐答案
MyDataContext DC = new MyDataContext();
var DS = from a in DC.MyTable select a;
DataTable DT = new DataTable();
DT.Columns.Add("Check", typeof(bool));
DT.Columns.Add("Value", typeof(string));
foreach (var item in DS)
{
DataRow DR = DT.NewRow();
DR[0] = false;
DR[1] = item.Value;
DT.Rows.Add(DR);
}
MyGridView.DataSource = DT;
这篇关于以简单的窗口形式向DataGridView添加复选框列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文