找回密码
 立即注册

QQ登录

只需一步,快速开始

topaz14

高级会员

4

主题

8

帖子

1586

积分

高级会员

积分
1586

活字格认证

topaz14
高级会员   /  发表于:2014-1-22 15:14  /   查看:6422  /  回复:7
请问有办法将右键菜单绑定到DataGrid的行上面吗,就是右键的时候能够直接选中一行。

7 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2014-1-22 18:15:00
沙发
回复 1楼topaz14的帖子

请参考以下代码:

  1.         void c1TrueDBGrid1_MouseDown(object sender, MouseEventArgs e)
  2.         {
  3.             if (e.Button== System.Windows.Forms.MouseButtons.Right)
  4.             {
  5.                 int row = 0;
  6.                 int col = 0;
  7.                 this.c1TrueDBGrid1.CellContaining(e.X,e.Y,out row,out col);
  8.                 this.c1TrueDBGrid1.SetActiveCell(row, col);
  9.             }
  10.         }
复制代码
回复 使用道具 举报
cy_liuquan
银牌会员   /  发表于:2014-10-9 17:49:00
板凳
你好 上面的方法中 datagrid没有取到cellcontain和setactioncell,以及e中没有X,Y两个参数
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2014-10-9 18:09:00
地板
回复 3楼cy_liuquan的帖子

你好,请问你的C1版本和平台是什么,另外是在什么事件下获取e.x和e.y的?
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
cy_liuquan
银牌会员   /  发表于:2014-10-10 09:14:00
5#
VS2010,C1也是studio for wpf 2010.4,用到的是鼠标点击事件
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2014-10-10 11:52:00
6#
回复 5楼cy_liuquan的帖子

你好,这里是WinForm版块。
WinForm和WPF是两种完全不同的机制,他们的事件也是不同的。
在WPF下,你可以使用如下方法右键选择行:
  1. private void c1DataGrid1_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
  2. {
  3.     foreach (var item in c1DataGrid1.Rows)
  4.     {
  5.         if (item.IsMouseOver)
  6.         {
  7.             c1DataGrid1.SelectedIndex = item.Index;
  8.             break;
  9.         }
  10.     }
  11. }
复制代码

评分

参与人数 1满意度 +5 收起 理由
cy_liuquan + 5 已经解决问题,

查看全部评分

请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
cy_liuquan
银牌会员   /  发表于:2014-10-10 16:33:00
7#
已解决 谢谢
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2014-10-10 17:21:00
8#
回复 7楼cy_liuquan的帖子

不用客气,欢迎参与评分。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部