简体   繁体   中英

event handler and datagrid

I have a little problem with handling SelectionChanged event in a datagrid control. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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