DX控件中鼠标双击(或鼠标右键同理)点击GridControl(GridView)的实现

据了解,dxexpress的数据表GridContral没有直接提供鼠标双击事件

可以样用一下方法替代实现。


// 鼠标点击事件(关联)
        private void caseDGView_MouseDown(object sender, MouseEventArgs e)
        {
            // 是否是双击(此控件无双击事件)
            if (e.Clicks != 2)
            {
                return;
            }

            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            //判断光标是否在行范围内
            if (caseDGView.CalcHitInfo(new Point(e.X, e.Y)).InRow == false)
            {
                return;
            }

            // 下面接着写想要实现的过程

            okBtn_Click(sender, e);
        }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Dev GridControl 控件GridView 显示学生信息,您需要进行以下修改: 1. 添加 `using DevExpress.XtraGrid;` 和 `using DevExpress.XtraGrid.Views.Grid;` 引用。 2. 将 `Program` 类修改为继承自 `DevExpress.XtraEditors.XtraForm`。 3. 在窗体上放置一个 `GridControl` 控件,并将其 Dock 属性设置为 `Fill`。 4. 将原来的 `MessageBox.Show` 改为使用 `gridView.SetRowCellValue` 方法将学生信息添加到 GridView 。 以下是修改后的示例代码: ```csharp using System; using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; using System.Windows.Forms; using DevExpress.XtraGrid; using DevExpress.XtraGrid.Views.Grid; public class UserInfo { public string Name { get; set; } public string Age { get; set; } public string Gender { get; set; } public string Phone { get; set; } public string Email { get; set; } } public class Program : DevExpress.XtraEditors.XtraForm { private GridControl gridControl; private GridView gridView; private Button extractButton; public Program() { gridControl = new GridControl(); gridView = new GridView(); extractButton = new Button(); extractButton.Text = "提取用户信息"; extractButton.Click += ExtractButton_Click; gridView.GridControl = gridControl; gridControl.Dock = DockStyle.Fill; gridControl.ViewCollection.Add(gridView); Controls.Add(gridControl); Controls.Add(extractButton); } private void ExtractButton_Click(object sender, EventArgs e) { string filePath = "path/to/your/txt/file.txt"; UserInfo userInfo = ExtractUserInfo(filePath); gridView.SetRowCellValue(0, "Name", userInfo.Name); gridView.SetRowCellValue(0, "Age", userInfo.Age); gridView.SetRowCellValue(0, "Gender", userInfo.Gender); gridView.SetRowCellValue(0, "Phone", userInfo.Phone); gridView.SetRowCellValue(0, "Email", userInfo.Email); } private UserInfo ExtractUserInfo(string filePath) { string content = File.ReadAllText(filePath); string name = GetMatchValue(content, @"姓名:([\w\s]+)"); string age = GetMatchValue(content, @"年龄:(\d+)"); string gender = GetMatchValue(content, @"性别:([\w\s]+)"); string phone = GetMatchValue(content, @"电话:(\d+)"); string email = GetMatchValue(content, @"邮箱:([\w\.]+@[\w\.]+)"); UserInfo userInfo = new UserInfo { Name = name, Age = age, Gender = gender, Phone = phone, Email = email }; return userInfo; } private string GetMatchValue(string content, string pattern) { Match match = Regex.Match(content, pattern); return match.Success ? match.Groups[1].Value : null; } public static void Main(string[] args) { Application.Run(new Program()); } } ``` 这个示例代码,我们添加了 `DevExpress.XtraGrid` 和 `DevExpress.XtraGrid.Views.Grid` 的引用,并使用 `GridControl` 和 `GridView` 控件来显示学生信息。 在点击按钮后,我们使用 `gridView.SetRowCellValue` 方法将学生信息添加到 GridView 的第一行。请确保将 `filePath` 替换为实际的文件路径。运行程序后,点击按钮即可触发提取操作,并将学生信息显示在 GridView 的第一行

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值