Wednesday, May 20, 2009

Disable Editing in DataGridView+Winforms

// Method 1

private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
if (((DataGridView)sender).CurrentCell.ColumnIndex == 1)
e.Cancel = true;
}

//Method 2

private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if(this.dataGridView1.CurrentCell.ColumnIndex==1)
this.dataGridView1.CurrentCell.Selected = false;
}

No comments:

Post a Comment

 
Locations of visitors to this page