I am writing a reservation application which utilizes a DataGridView to list the available rooms down the Y axis and the available times on the X axis as the columns.
I would like the user to be able to drag select a time frame, but it has to be limited to one row at a time.
Either controlling the highlight aspect of the grid so only the desired row is highlighted when the mouse moves or capturing the mouse within the rows bounds are the options I have thought of. Any help in implementation either of these or even a new way to handle the task are all welcome!
I would prefer to just capture the mouse with the DataRow where the mouse down event occurs, not sure if I have to use a clipping rectangle to achieve this or not.
Thanks in advance for any help.
As an improvement on your CellStateChanged event code, the below could be used.
The differences in this for-loop is the usage of
e.Cell
as a reference point forRowIndex
sincee.Cell
is the cell that was selected by the user, setting ofe.Cell.Selected
tofalse
instead ofcell.Selected
and finally abreak;
in the for-loop since after the firstRowIndex
mismatch, we can stop the checking.