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