Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, Iam using VS2010. I have a DataGridViewComboBoxColumn in DataGridView. I wish to set the cursor to that column, Is it possible?

C#
MyDGVComboBoxColumn.Cursor = Cursors.Hand;


Thanks
Posted
Updated 12-Jun-14 19:59pm
v3

1 solution

You cannot directly do it, because columns of the DataGridView are not controls. You can try to achieve desired effect by modifying the property Cursor of this control, depending on the current location of the mouse withing the control, using columns widths to calculate the location of each columns. You can handle the change in mouse location by handling the event MouseMove of the control.

Please see:
http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.control.cursor[^],
http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.control.mousemove[^].

Another, perhaps simpler and more efficient approach would be handling the events CellMouseEnter and CellMouseLeave. This way, you can capture moving your mouse cursor from cell to cell and, analyzing the values of the cell property DataGridViewCell.ColumnIndex for "previous" and "current" cell, you can figure out if you are leaving or entering the column in question. When such event of crossing of the column boundary is captured, you can again use the property DataGridView.Cursor to change the cursor appearance.

http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.datagridview.cellmouseenter[^],
http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.datagridview.cellmouseleave[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.columnindex(v=vs.110).aspx[^].

I think those instructions are quite clear, you just have to implement them.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900