使用DataGridView复选框列作为字符串数据列 [英] Use DataGridView CheckBox Column for a string data column
问题描述
我在数据库中有这个表:
模块|日期|批准|
xxxx xxxx xxxx xxxxxxx
yyyy yyyy yyyy yyyyyy
tttt tttt tttt ttttttt
我有这个数据库表。查询后我将
DataTable
分配给我的 DataGridView.DataSource
:
QueryAssist qa = new QueryAssist();
DataTable dt = new DataTable();
dt = qa.runQuery('myquery');
dgvApprovazione.DataSource = dt;
dgvApprovazione.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
//修改,转换cellLink中的第二列
foreach(dgvApprovazione.Rows中的DataGridViewRow行)
{
row.Cells [1] = new DataGridViewLinkCell ;
}
现在我想转换列 approving
这是一个字符串批准
或未批准
,并显示一个复选框。
如果此单元格的值为已批准
复选框处于选中状态且未修改(只读)。
类似:
foreach(dgvApprovazione.Rows中的DataGridViewRow行)
{
if(row.Cells [3] .Value.ToString()。Equals(APPROVED))
{
row.Cells [3] = new DataGridViewCheckBoxCell
}
}
我有一个问题要实现...帮助我。
这可能吗?如何?
重新映射:
我想更改包含的值为文本/字符串
对不起,英语不好。
好的替代品?
要储存是/否或开启/关闭 em> true / false 值,最好在sql server中使用位
数据类型,但使用 DataGridViewCheckBoxColumn
a>您还可以通过设置 TrueValue
和 FalseValue
属性。
在下面的例子中,我假定你在数据库中有一个可以为空的列,需要存储 要这样做,您应该使用设计器或代码添加您的列: 这样您就可以显示已核准或未核准的核取方块,也可以使用复选框。 如果您不需要编辑它们并且只想显示它们,您可以将该列的只读属性设置为true。 I have this table in database: I have this db table. After query I assign
Now I want to transform column if value of this cell is something similar: I have a problem to implement ... help me. It's possible ? How? recapping: I want to change a column that value contain is a text/string (approved or not approved ) in checkbox (checked or unchecked) Sorry for bad english .. Good alternatives? To store yes/no or on/off or true/false values in database, it's better to use In the below example I supposed you have a nullable column in database which needs to store values as To do so, you should add your column this way using designer or code: This way you show approved or not approved as check boxes, also you are able to edit those values using check box. If you don't need to edit them and only want to show them, you can set read only property of the column true. 这篇关于使用DataGridView复选框列作为字符串数据列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! APPROVED
或 NOTAPPROVED
作为
nvarchar(50)
,您需要使用 DataGridViewCheckBoxColumn
p>
var column1 = new DataGridViewCheckBoxColumn();
column1.Name =column1; //列名称
column1.HeaderText =已批准; // column of
column1.DataPropertyName =approvation; //数据库中的归档名称
column1.TrueValue =APPROVED; // True value
column1.FalseValue =NOTAPPROVED; // False Value
this.dataGridView1.Columns.Add(column1);
applicant | module | date | approvation |
xxxx xxxx xxxx xxxxxxx
yyyy yyyy yyyy yyyyyyy
tttt tttt tttt ttttttt
DataTable
to my DataGridView.DataSource
:QueryAssist qa = new QueryAssist();
DataTable dt = new DataTable();
dt = qa.runQuery('myquery');
dgvApprovazione.DataSource = dt;
dgvApprovazione.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
// modify, transform 2nd column in cellLink
foreach (DataGridViewRow row in dgvApprovazione.Rows)
{
row.Cells[1] = new DataGridViewLinkCell();
}
approvation
that is a string approved
or not approved
and show a check box instead.approved
check box is checked and not modified (onlyread).foreach (DataGridViewRow row in dgvApprovazione.Rows)
{
if (row.Cells[3].Value.ToString().Equals("APPROVED"))
{
row.Cells[3] = new DataGridViewCheckBoxCell();
}
}
bit
data type in sql server, but using a DataGridViewCheckBoxColumn
you can show and edit also a string column by setting TrueValue
and FalseValue
properties.APPROVED
or NOTAPPROVED
as nvarchar(50)
and you need to edit those values using DataGridViewCheckBoxColumn
.var column1 = new DataGridViewCheckBoxColumn();
column1.Name = "column1"; //Name of column
column1.HeaderText= "Is Approved"; //Title of column
column1.DataPropertyName = "approvation"; //Name of filed in database
column1.TrueValue = "APPROVED"; //True value
column1.FalseValue = "NOTAPPROVED"; //False Value
this.dataGridView1.Columns.Add(column1);