右键点击网格行 [英] right click on grid row

查看:177
本文介绍了右键点击网格行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是,每当网格的行右键单击所选项目时,都会为null。如果任何行被右击,我是否会选择网格的行?

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?

感谢
Jamal

thanks Jamal

推荐答案

可能有问题。每次加载一行时,它将添加一个事件处理程序,因此如果该行被重用,它可以累积事件处理程序。我建议删除行卸载时的事件处理程序。这是我建议的代码:

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);
}

这篇关于右键点击网格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆