如何在Datagridview中隐藏特定单元格的CheckBox [英] How to hide CheckBox for particular cell in Datagridview
本文介绍了如何在Datagridview中隐藏特定单元格的CheckBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个未绑定的datagridview,其中填充了数据,有些列是复选框列,
我想根据值
连续读取一个单元格
我想在某些单元格中隐藏一个复选框,以便用户看不到它.我该怎么做.
Hi ,
I have an unbound datagridview populated with data, some columns are checkbox columns,
I would like to read a cell in a row and based on the value
I would like to hide a checkbox in certain cells so that the user does not see it. How can I do this please.
推荐答案
使用CellPainting事件
use the CellPainting event
private void Grid_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
if (Grid.Columns[e.ColumnIndex].Name == "CheckBoxColumn" && Grid.Rows[e.RowIndex].Cells["ColumnToCheck"].Value == <TrueHideValue>)
{
e.PaintBackground(e.ClipBounds, true);
e.Handled = true;
}
}
}
您可以在Datagrid的ItemDataBound事件中执行此操作.
在FindColumnByUniqueName的帮助下搜索所需的列,然后可以隐藏该列.试试看...
谢谢
-------------
Amith V.A.
Hi,
You can do that in ItemDataBound event of Datagrid.
Search the column you want with help of FindColumnByUniqueName and you can hide that column. Give a try...
Thank you,
-------------
Amith V.A.
您可以在datagrid的ItemDataBound事件期间进行处理:
在这种情况下,当数据逐行绑定时,请添加以下内容:
You can handle this during ItemDataBound event of the datagrid:
In this event, while the data is binded row by row - add something like:
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
//
//
//This textbox has the value of the cell based on which you need to hide checkbox
Textbox txtCheckValue = (Textbox)e.Row.FindControl("Textbox1");
//Check the value condition as per your wish
if(txtCheckValue_SatisfyCertainCondition())
{
Checkbox chkCurrRow = (Checkbox)e.Row.FindControl("Checkbox1");
// set visibility of your control
chkCurrRow.Visible = false;
}
//
//
}
这篇关于如何在Datagridview中隐藏特定单元格的CheckBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文