Hi,
I have a check box column. I would like to select the rows when the user clicks on the checkbox.
Currently the rows are not gettting selected on when checkbox is checked. How to select multiple rows programmatically.
thanks,
I don't think this is feasible. You are going to lose the selection if the user clicks on another row or attempts to edit another cell, for example.So as soon as the user clicks a checkbox in other row, you will lose the selection on any previously-selected rows. So you really cant use Selection for this.
If you want to highlight the checked rows, I recommend storing a list of rows yourself. Then in the InitializeRow event you can check if e.Row is on your list of Checked rows and if so, apply an Appearance to the row.
I am setting the row.selected = true when the user clicks the check box. According to the documentations setting the Selected property adds the row to the SelectedRowCollections. So ideally this should select multiple rows in the grid.
Please let me know if this should work or not.
Thanks,
Swati
Hi Swati,
The easiest thing for you to do would be to try it out and see if it works. But I don't think it will. You cannot have selected rows and also edit a cell at the same time. Once a cell enters edit mode, then you will lose the selected rows. So you can click a CheckBox and select the row, but as soon as you click any other cell that goes into edit mode, including any other checkbox cell, the previously selected row will be de-selected.
Mike, is there a work around that is used for this? It doesn't make sense to me that enter a edit mode on a cell would change the selected row? For example, if I edit a cell in the currently selected row, the row should remain selected. If I enter edit more on a cell in a different row, THAT row should become the selected row.
This makes it much easier to handle keyboard-style navigation - e.g. - while editing a cell, the user can type Alt-X to execute without having to leave the cell and re-select the row by clicking on some non-editable cell.
I don't see any way to do this. The problem is that as soon as a cell enters edit mode, all previous selected rows are unselected. There's no way around this. Or at least no simple way.
One way you could acheive this is to turn off selection of rows in the grid and then handle the selection yourself. Basically, this would mean handling the MouseDown event and keeping your own list of "selected" rows. Then you could use the InitializeRow event to apply an appearance to those rows so they appear selected to the user. This way, when the user edits a cell, you simply don't clear the selection. But you would essentially have to re-implement all of the selection logic you need like dragging across rows, range selection, non-contguous selection, etc.
Ah I meant something slightly different. What I mean is I would like a work-around that means putting a cell in Edit mode implies that its ROW is in SelectedRows. If you multiple selected something, nothing would be in edit mode, but if you then entered edit mode, the selected rows would change to include only the currently editable cell's row.
Is that something that's possible? Or do I have to track changes to the SelectedRows and Editable cell myself?
This is pretty much the way it works with all Windows applications and controls that I know of. Selecting multiple rows and editing an individual item are mutually exclusive.
The easiest thing to do would be to use something else for "selected". Like, for example, you could use an unbound CheckBox column in the grid. That way, the checked columns would not be affected by editing a cell.