获取 C1TrueDBGrid 鼠标所在位置的单元格信息

发布时间:2013/06/25 00:06 发布者:jian

返回博客中心

在 C1TrueDBGrid for WinFroms 中没有提供直接获取鼠标所在位置单元格信息的方法 GetCellFromPoint,不过在 C1TrueDBGrid for WinForms 中提供了 ColContaining 和 RowContaining 方法可获取鼠标所在位置的单元格行列值,实现代码如下:

    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }
        private void Form3_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("第一列");
            dt.Columns.Add("第二列");
            dt.Columns.Add("第三列");
            dt.Rows.Add("A1", "B1", "C1");
            dt.Rows.Add("A1", "B1", "C1");
            dt.Rows.Add("A1", "B1", "C1");
            dt.Rows.Add("A1", "B1", "C1");
            c1TrueDBGrid1.DataSource = dt;
            c1TrueDBGrid1.MouseMove += new MouseEventHandler(c1TrueDBGrid1_MouseMove);
        }
        void c1TrueDBGrid1_MouseMove(object sender, MouseEventArgs e)
        {
            C1.Win.C1TrueDBGrid.C1TrueDBGrid tdbgrid = sender as C1.Win.C1TrueDBGrid.C1TrueDBGrid;
            // 获取鼠标所在位置的单元格
            Point p = tdbgrid.PointToClient(Control.MousePosition);
            Point curRowCol = new Point(tdbgrid.ColContaining(p.X), tdbgrid.RowContaining(p.Y));
            toolStripStatusLabel1.Text = string.Format("({0},{1})",curRowCol.Y,curRowCol.X);
        }
    }

 

运行截图:

C1TrueDBGrid


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网