c#删除checkbox选中的行gridcontrol
时间: 2023-08-02 16:10:35 浏览: 111
假设你正在使用 DevExpress 控件库中的 GridControl 控件,你可以按照以下步骤删除选中的行:
添加一个列,类型为 RepositoryItemCheckEdit,用于显示复选框。
在 GridControl 的 CustomUnboundColumnData 事件中添加以下代码:
private void gridControl1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
if (e.Column.FieldName == yourCheckBoxColumn.FieldName && e.IsGetData)
{
e.Value = false; // 给复选框列设置默认值
}
if (e.Column.FieldName == yourCheckBoxColumn.FieldName && e.IsSetData)
{
bool isChecked = (bool)e.Value;
if (isChecked)
{
gridView1.DeleteRow(e.RowHandle);
}
}
}
在这段代码中,yourCheckBoxColumn 是你刚刚添加的 RepositoryItemCheckEdit 列的名称,gridControl1 是你的 GridControl 控件的名称,gridView1 是你的 GridView 视图对象的名称。
以上代码的作用是:当用户选中复选框时,检查该行的复选框是否被选中,如果选中,则将该行从 GridControl 中删除。
希望这可以帮助到你!
相关推荐


















