Ok let me see if I can explain what I want to do...
I have grid with a Selection Overlay. The user selects several rows and at this point the Active Row/Cell is on the last row in "selected". Now when the user click on a row the selection overlay is reset to the last row.
What I want, is that if the user clicks on a cell anywhere in the "selected" rows, the selection is maintained when the cell goes into edit mode.
The idea, is I want the user to be able to enter values in one cell and have the values in the same cell on other selected rows change to what the user has entered in the active cell. My problem is, as soon as I "active" a cell the selection overlay clears.
Ideally, if the user clicked on a row that was NOT in the selection then it would clear the selection. if they click a row that IS in the selection it would maintain the selection.
Here is an example:
The grid has several rows selected.
Now I want to go and enter a value in the "One Plug" column and then have all the rows have the same value.
But as soon as I click on a the "One Plug" cell, it puts clear s the selection.
I'm not worried about updating the values in the other cells. I know that I will have to use the SelectedRows collection in the CellChange event handler. I know how to do this.
But I need the selection to be "sticky". So is there an easy way to do this? The setting has not popped out at me. I'm playing with Before and After Row active to see if I can make it work. But I thought I would ask before I spent to much time hacking around...
Dan
Hi Dan,
This is not possible. Any time a cell goes into edit mode, the grid will clear any selected rows. There is no way to prevent this.
The only way you could achieve this would be to turn off the grid's built-in row selection functionality and then handle all of the mouse and keyboard interaction with the grid yourself - essentially re-implementing row selection yourself.
This would, of course, be terribly difficult and complex.
EDIT: Another idea just occurred to me. What if, instead of using Selection, you used a CheckBox? You could add an unbound column to the grid and set it's DataType to Boolean. Then you could keep a collection of the "checked" rows. You could use the InitializeRow event to highlight the checked rows (although it would be difficult to provide a selection overlay, so you would probably have to just use a solid color to highlight the rows).
This would allow you to control which rows are checked. You could clear (uncheck) the checked rows when a cell in an unchecked row goes into edit mode, and do nothing when a cell goes into edit mode on a checked row.
Thanks Mike,
Yeah I kind of figured out that the selection wasn't going to hold last night. I did pretty much what you had suggested. Basically made a copy of the selected collection after each fire of the Before Activate Row event. Then I had it go thru in the After Activate Row event and set the "select" state of each row.
It was fun to watch, the overlay would go away, and then you could watch the rows select, and then you could watch it dissappear. Figured I was hosed.
However, your suggestion is geinus! That will work. I don't event think I will need the checkbox. I can just use the copy of the selection collection I already have. Now the only question is will the Init Row event fire on the rows that I need to change the background color on.
I'm off to see if it works! Thanks again!
danhsoho said:Now the only question is will the Init Row event fire on the rows that I need to change the background color on.
It probably won't, since it has no reason to. But you loop through those rows and make it fire by calling:
row.Refresh(RefreshRow.FireInitializeRow);
Of, you could make it fire for all rows like so:
this.ultraGrid1.Rows.Refresh(RefreshRow.FireInitializeRow);
Ok so I got it working exactly how I wanted it to work.
You see here that I have a group of rows selected.
Then when I click on one of the editble cells, it highlights the cells that are being massed updated.
Then as I type the values are automatically filled in down the grid.
This is VERY sweet! Thanks so much for pointing me in the right direction. It woks exactly how I want it to. Now I'm going to go see if I can use a draw filter to put a nice thick border around the block and then it will be perfect!
I also need to see if I can package the code up into a snippet so that I can drop it on any grid. I think I will use this over and over. Of course everytime I figure something like this out I have to decide if I want to go back to other grids and add this functionality.
Thanks for your help! Again!
Actually it wasn't even necessary. I just set the rows appearance when I added it to the "holding" array of the selected items.
This is going to work great. I'm not quite done yet, but I'm going to be able to highlght just the cell that is getting updated instead of the whole row. I just about got it. I'll post you and update with how I got it to work once I'm done!
Again thanks for your geinus! I would like to think your solution would have come to me once I woke up this morning, but you have saved me hours of "thinking" about it.