我想在 Windows 窗体应用程序中将列值显示为true
或false
代替复选框作为列值DataGridView
。实际上在数据库中,该表具有在将表值绑定到 时或同时IsPaymentCard
具有值的列。在列中的值显示为复选框而不是或。我想将值显示为.1
0
DataGridView
DataGridView
IsPaymentCard
1
0
boolean
我试过如下
dataGridView1 .DataSource = wsobj.Get(connec,comand,"tablename");// binded through webservice
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (Convert.ToBoolean(row.Cells["IsPaymentCard"].Value) == true)
{
row.Cells["IsPaymentCard"].Value = "True";
}
else row.Cells["IsPaymentCard"].Value = "False";
}
提前致谢。
将复选框与布尔值绑定
DataTable dtEmp = new DataTable();
// add column to datatable
dtEmp.Columns.Add("IsPresent", typeof(bool));
dtEmp.Columns.Add("EmpID", typeof(int));
dtEmp.Columns.Add("EmpName", typeof(string));
dtEmp.Rows.Add(true, 111, "ABC");
dtEmp.Rows.Add(false, 444, "DEF");
DataTable newDataTable = dtEmp.Clone();
foreach (DataColumn dc in newDataTable.Columns)
{
if (dc.DataType == typeof(bool))
{
dc.DataType = typeof(string);
}
}
foreach (DataRow dr in dtEmp.Rows)
{
newDataTable.ImportRow(dr);
}
dataGridView1.DataSource = newDataTable;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句