right click on grid row

南笙酒味 提交于 2019-12-12 03:53:07

问题


problem is , that whenever the grid's row is right clicked the selected item is null.how do i make a the grid's row selected when any row was right clicked?

thanks Jamal


回答1:


I think the solution may have a problem. Every time a row is loaded it will add an event handler, so if the row is ever reused it can accumulate event handlers. I would recommend removing the event handler when the row is unloaded. Here's my suggested code:

private void dg_LoadingRow(object sender, DataGridRowEventArgs e)
{
    e.Row.MouseRightButtonDown += new MouseButtonEventHandler(Row_MouseRightButtonDown);
}
void Row_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
    dg.SelectedItem = ((sender) as DataGridRow).DataContext;
}
// new portion
private void dg_UnloadingRow(object sender, DataGridRowEventArgs e)
{
    e.Row.MouseRightButtonDown -= new MouseButtonEventHandler(Row_MouseRightButtonDown);
}



回答2:


here is the solution

http://forums.silverlight.net/forums/t/171088.aspx



来源:https://stackoverflow.com/questions/2532485/right-click-on-grid-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!