Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 仅在DataGridView的特定列上使用手动光标_C#_Winforms_Datagridview - Fatal编程技术网

C# 仅在DataGridView的特定列上使用手动光标

C# 仅在DataGridView的特定列上使用手动光标,c#,winforms,datagridview,C#,Winforms,Datagridview,我正在用C#编写一个表单应用程序,我有一个DataGridView,它显示来自SQL server的数据。 这些数据包含一个名为Remove的列,该列的所有行都包含字符串Remove。现在,我想通过改变背景颜色和使用手动光标,使该列的所有单元格看起来像一个按钮 我的问题是,我不能仅在该列上使用手动光标。我想要的是,当鼠标位于Remove列的任何行上时,将鼠标指针更改为手动光标,而不是其他任何位置 for(int i=0; i<myDataGridView.RowCount; i++){

我正在用C#编写一个表单应用程序,我有一个DataGridView,它显示来自SQL server的数据。 这些数据包含一个名为
Remove
的列,该列的所有行都包含字符串Remove。现在,我想通过改变背景颜色和使用手动光标,使该列的所有单元格看起来像一个按钮

我的问题是,我不能仅在该列上使用手动光标。我想要的是,当鼠标位于
Remove
列的任何行上时,将鼠标指针更改为手动光标,而不是其他任何位置

for(int i=0; i<myDataGridView.RowCount; i++){
    myDataGridView.Cursor = Cursors.Hand;
}
但这会产生一个错误:

System.Windows.Forms.DataGridViewColumn不包含“游标”的定义


有什么好办法可以做到这一点吗?谢谢。

尝试点击DataGridView的OnCellMouseEnter事件。一旦触发事件,您可以确定单元格所在的列,并根据需要更改光标。

使用此代码,它对我有用

    private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            string colname = dataGridView1.Columns[e.ColumnIndex].Name;
           if(colname!="btnEdit" && colname!= "btnDelete")
            {
                dataGridView1.Cursor = Cursors.Default;
            }
            else
            {
                dataGridView1.Cursor = Cursors.Hand;
            }
        }

若您希望列看起来像按钮,那个么使用。
    private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            string colname = dataGridView1.Columns[e.ColumnIndex].Name;
           if(colname!="btnEdit" && colname!= "btnDelete")
            {
                dataGridView1.Cursor = Cursors.Default;
            }
            else
            {
                dataGridView1.Cursor = Cursors.Hand;
            }
        }