开发者

Catching focus out event of a datagrid

I want to catch the foc开发者_如何学Cus out event of a datagrid so that everytime, datagrid in edit mode focuses out, I should be able to close out the edit mode.


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
}


http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.celleditending.aspx


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜