Reputation: 3105
I want to catch the focus out event of a datagrid so that everytime, datagrid in edit mode focuses out, I should be able to close out the edit mode.
Upvotes: 2
Views: 5739
Reputation: 343
I think you don't want to let user edit cells values if that
use the dataGridView CellBeginEdit event
dataGridView1.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.dataGridView1_CellBeginEdit);
and then cancel then edit in event handling
private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
e.Cancel = true;
}
i hope this help.
Upvotes: 1
Reputation: 18430
You can use the LostFocus event to do this.
//Short Version
gridview1.LostFocus += (sender, e) => {//Your code to close edit mode};
Or normally you would do it as:
//Normal long Version
gridview1.LostFocus += new EventHandler(gridview1_LostFocus);
some where define your method for event handeling
public void gridview1_LostFocus(object sender, RoutedEventArgs e)
{
//Your code to close edit mode
}
Upvotes: 3
Reputation: 5914
http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.celleditending.aspx
Upvotes: 1