Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 防止编辑DataGridView中的特定行_C#_.net 3.5_Datagridview - Fatal编程技术网

C# 防止编辑DataGridView中的特定行

C# 防止编辑DataGridView中的特定行,c#,.net-3.5,datagridview,C#,.net 3.5,Datagridview,我想阻止用户编辑或删除datagridview的前三行 如何执行此操作?一种方法是捕获_CellBeginEdit事件,检查是否允许对目标行进行任何编辑,如果不允许编辑,则取消事件: 私有void DataGridViewIndexSpecs_CellBeginEdit(对象发送方,DataGridViewCellCancelEventArgs e) { if(e.RowIndex一种方法是捕获_CellBeginEdit事件,检查是否允许对目标行进行任何编辑,如果不允许编辑,则取消事件: 私有

我想阻止用户编辑或删除datagridview的前三行


如何执行此操作?

一种方法是捕获_CellBeginEdit事件,检查是否允许对目标行进行任何编辑,如果不允许编辑,则取消事件:

私有void DataGridViewIndexSpecs_CellBeginEdit(对象发送方,DataGridViewCellCancelEventArgs e) {


if(e.RowIndex一种方法是捕获_CellBeginEdit事件,检查是否允许对目标行进行任何编辑,如果不允许编辑,则取消事件:

私有void DataGridViewIndexSpecs_CellBeginEdit(对象发送方,DataGridViewCellCancelEventArgs e) {

if(e.RowIndex解决方案:

private void dataGridView3_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) {
    if (e.RowIndex < 3) {
        e.Cancel = true;
    }
}

private void dataGridView3_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) {
    if (e.Row.Index < 3) {
        e.Cancel = true;
    }
}
private void dataGridView3\u CellBeginEdit(对象发送方,DataGridViewCellCancelEventArgs e){
如果(e.RowIndex<3){
e、 取消=真;
}
}
私有void dataGridView3_UserDeletingRow(对象发送者,DataGridViewRowCancelEventArgs e){
如果(例如,行索引<3){
e、 取消=真;
}
}
解决方案:

private void dataGridView3_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) {
    if (e.RowIndex < 3) {
        e.Cancel = true;
    }
}

private void dataGridView3_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) {
    if (e.Row.Index < 3) {
        e.Cancel = true;
    }
}
private void dataGridView3\u CellBeginEdit(对象发送方,DataGridViewCellCancelEventArgs e){
如果(e.RowIndex<3){
e、 取消=真;
}
}
私有void dataGridView3_UserDeletingRow(对象发送者,DataGridViewRowCancelEventArgs e){
如果(例如,行索引<3){
e、 取消=真;
}
}

这是否也会阻止他们删除它?这是否也会阻止他们删除它?