本文介绍了在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

推荐答案

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.
                    }
                }
            }
        }



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

10-27 14:07