T
Tim Rogers
I'm trying to allow the user to select a row in a datagrid by right
clicking on it (so that I can select the row and then a context menu is
displayed). In the DataGrid MouseDown event handler, I call HitTest on the
DataGrid (supplying the mouse X and Y positions). If a row is selected
(i.e. the mouse pointer is on a row), then I want to de-select any selected
row, and then select the row that is being right clicked. The hit test is
working, but the selecting and unselecting of rows is not.
1) How do I unselect any selected rows? I have tried to use the DataGrid's
Unselect method (passing in the CurrentRowIndex), but this does not seem to
work. Someone else suggested calling ResetSelection(), but it's a protected
member.
2) How do I select a row? When I use the DataGrid's Select() method, the
row becomes 'highlighted', but not selected. I can verify this by
attempting to select a row via Select(), and then check the DataGrid's
CurrentRowIndex property. It doesn't change, and you can see the effects
visually (i.e. that the row I wanted selected isn't selected).
FYI - In case it matters, I don't have the datagrid bound to a database or
anything like that. I'm am bound to a DataSet object which uses a DataTable
object that I am manipulating dynamically via my code.
Any help would be much appreciated.
Thanks,
Tim Rogers
clicking on it (so that I can select the row and then a context menu is
displayed). In the DataGrid MouseDown event handler, I call HitTest on the
DataGrid (supplying the mouse X and Y positions). If a row is selected
(i.e. the mouse pointer is on a row), then I want to de-select any selected
row, and then select the row that is being right clicked. The hit test is
working, but the selecting and unselecting of rows is not.
1) How do I unselect any selected rows? I have tried to use the DataGrid's
Unselect method (passing in the CurrentRowIndex), but this does not seem to
work. Someone else suggested calling ResetSelection(), but it's a protected
member.
2) How do I select a row? When I use the DataGrid's Select() method, the
row becomes 'highlighted', but not selected. I can verify this by
attempting to select a row via Select(), and then check the DataGrid's
CurrentRowIndex property. It doesn't change, and you can see the effects
visually (i.e. that the row I wanted selected isn't selected).
FYI - In case it matters, I don't have the datagrid bound to a database or
anything like that. I'm am bound to a DataSet object which uses a DataTable
object that I am manipulating dynamically via my code.
Any help would be much appreciated.
Thanks,
Tim Rogers