简体   繁体   English

事件处理程序和数据网格

[英]event handler and datagrid

I have a little problem with handling SelectionChanged event in a datagrid control. 我在处理datagrid控件中的SelectionChanged事件时遇到了一些问题。 I would like to display simply a message when the user selects another row. 当用户选择另一行时,我只想显示一条消息。 The displayed message box is ok, things work fine but the selection is slowed because I call the event like this 显示的消息框正常,一切正常,但选择速度变慢,因为我这样调用事件

private void dgemp_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    MessageBox.Show(((Emplooyee)dgemp.SelectedItem).fullname);
}

That is, only when I close the message box will I see the selection highlight appear on the datagrid. 也就是说,只有当我关闭消息框时,我才会看到选择突出显示在数据网格上。 Is there a method or another event I can use or call to make it select the row at once ? 有没有可以使用或调用的方法或其他事件,使其立即选择该行?

Use this: 用这个:

private void dgemp_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
    MessageBox.Show(((Emplooyee)dgemp.SelectedItem).fullname);
}

The MessagebBox is modal and will pause execution while it is open. MessagebBox是模态的,在打开时将暂停执行。 My suggestion is to create a separate window to display your message in, display your message in a separate control in the window with your DataGrid or you could try using Dispatcher.BeginInvoke to create your MessageBox asynchronously. 我的建议是创建一个单独的窗口来显示您的消息,在您的窗口中使用DataGrid在单独的控件中显示您的消息,或者您可以尝试使用Dispatcher.BeginInvoke异步创建您的MessageBox。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM