在DataGridViewCell Hover上更改鼠标光标 [英] Change mouse cursor on DataGridViewCell Hover

查看:183
本文介绍了在DataGridViewCell Hover上更改鼠标光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的DataGridView(dgv)

I have DataGridView(dgv) like this

No name Edit(Link column)
1   A   Edit
2   B   Edit
3   C   Edit



我想显示等待光标,如果它在编辑单元格,其中否= 2

和手形光标用于重新获得记录。

提前感谢


I want display Wait cursor if it is on Edit cell where No=2
and Hand cursor for reaining records.
thanks in advance

推荐答案

嘿,

此链接将帮助你

http://social.msdn.microsoft.com / forums / zh-CN / winformsdatacontrols / thread / 67ca0792-b603-4255-a2d0-c608f7c8512d [ ^ ]



祝你好运
hey,
this link will help u
http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/67ca0792-b603-4255-a2d0-c608f7c8512d[^]

best luck


CellMouseEnter 事件 DataGridView 控件可用于此目的,如下所示

The CellMouseEnter event of DataGridView control can be used for this purpose as shown below
private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e) 
{
    //Skip the Column and Row headers
    if (e.ColumnIndex < 0 || e.RowIndex < 0) {
        return;
    }
    var dataGridView = (sender as DataGridView);
    //Check the condition as per the requirement casting the cell value to the appropriate type
    if (e.ColumnIndex == 2 && (string)dataGridView.Rows[e.RowIndex].Cells[0].Value=="2")
        dataGridView.Cursor = Cursors.WaitCursor;
    else
        dataGridView.Cursor = Cursors.Hand;
}


private void YourDataGrideView_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (YourDataGrideView.Columns[e.ColumnIndex]=='your col index')
            {
                YourDataGrideView.Cursor = Cursors.Hand;
            }
            else
                YourDataGrideView.Cursor = Cursors.Default;
        }

        private void YourDataGrideView_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
        {
            YourDataGrideView.Cursor = Cursors.Default ;
        }


这篇关于在DataGridViewCell Hover上更改鼠标光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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