在MouseMove事件中获取dataGridView行的索引 [英] Getting the Index of a dataGridView Row in the MouseMove Event

查看:81
本文介绍了在MouseMove事件中获取dataGridView行的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想知道如何获取dataGridView的MouseMove事件中鼠标经过的dataGridView行的索引吗?

非常感谢您

Hello,

I want to know how I can get the index of a dataGridView Row over which the mouse is passing in the MouseMove Event of dataGridView?

Thank you very much

推荐答案

使用此代码可能会帮助您......

use this code may be it will help you......

private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                if (!((DataGridViewRow)(dataGridView1.Rows[e.RowIndex])).Selected)
                {
                    dataGridView1.ClearSelection();
                    ((DataGridViewRow)dataGridView1.Rows[e.RowIndex]).Selected = true;
                    if (dataGridView1.SelectedRows.Count > 0)
                    {
                        DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[e.RowIndex];
                        TextBox1.Text = e.RowIndex.ToString();// return row index of dataGridView On CellMouseMove Event and Display RowIndex in TextBox1.
                    }
                }
            }
        }


e.RowIndex和e.ColumnIndex将在DataGridView的CellMouseMove事件处理程序中返回RowIndex和ColumnIndex
e.RowIndex and e.ColumnIndex will return the RowIndex and ColumnIndex in the CellMouseMove Event Handler of the DataGridView


这篇关于在MouseMove事件中获取dataGridView行的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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