In the XamGrid, what is the best way to change the mouse cursor (to a hand) upon mouse-over cells in a particular column?
Hello Andy99,
I was looking into your question and I believe that depending on your specific scenario, different approaches may be more suitable for changing the mouse cursor. If the specific column you are referring is from type TemplatedColumn you can just set the Cursor property of the controls you use in the template. If this is not your case, I can suggest you handle the MouseEnder event for the CellControl and use the following code snippet:
void Control_MouseEnter(object sender, MouseEventArgs e)
{
if ((sender as CellControl).Column.Key == "Name")
this.Cursor = Cursors.Hand;
else
this.Cursor = Cursors.Arrow;
}
If you have any further questions on the matter, please do not hesitate to ask.
Elena,
Thanks for your reply. Could you please clarify in which grid event I can use to assign this event handler to the cellcontrol?
XamDataGrid exposes event named CellControlAttached, which you can use to set a different properties for a cell when it is loaded. This is why I believe that it is suitable to add the handler of the MouseMove event there.
private void xamGrid1_CellControlAttached(object sender, CellControlAttachedEventArgs e)
e.Cell.Control.MouseEnter += new MouseEventHandler(Control_MouseEnter);
Please let me know if this doesn’t suit your scenario.
No, this does not work - please see the attached example and advise.
For some reason I get an error message when I try to run the sample. However I have a look at your code and I notice that you have set the cursor for the CellControl. After some investigation I noticed that the XamGrid handles differently this scenario and for the CellControl, so I can suggest you set the cursor directly on the Cursor property of the window:
Please let me know if this still doesn’t suit your scenario.
Thanks Elena, this works now.
Please note that I also had to implement a MouseLeave event to make sure that the pointer would get reset when leaving the cell.
The reason my example solution had errors is because I changed the references to the Infragistics Components as I did not want to include those dlls. If you wanted to get it to work I would suggest you remove the references to the 3 Infragistics dlls and re-add them.