Listbox与dataGridView的获取鼠标点击事件的区别!!!

 1 int index = lisxian.IndexFromPoint(e.X, e.Y);//获取鼠标点击 2 lisxian.SelectedIndex = index; 

Listbox获取鼠标的代码!!!!

 1 int index = e.RowIndex; 2 DataGridViewRow currenRow = this.dgvxian3.Rows[index]; 

 dataGridView获取鼠标代码!!!!

 

 private void lisxian_SelectedIndexChanged(object sender, EventArgs e)

        {



        }



        private void lisxian_MouseClick(object sender, MouseEventArgs e)

        {

            int index = lisxian.IndexFromPoint(e.X, e.Y);

            lisxian.SelectedIndex = index;

            na1 = int.Parse(this.lisxian.SelectedValue.ToString());

            //MessageBox.Show("前一按钮为" + na1);

        }

当鼠标坐标发生改变时(即鼠标所点击位置属性改变时)发生的事件,在

MouseClick里写事件,但注意的是要与
SelectedIndexChanged(Listbox的默认事件)事件一起使用!

----来自凌波小屋----冯和超的笔记----

 

你可能感兴趣的:(datagridview)