I have a grid with two columns that contain comboboxes. The combobox list of the first column is static for all rows. The list displayed for the second combobox is dependent on the selection made in the first and is handled in the CurrentCellMoved event. My problem is when the user selects multiple rows in the grid and makes a selection from the second combobox, the row that contains the CurrentCell displays the correct selection but the other rows do not. I believe that second combobox list for the non-CurrentCell rows is not being reloaded, since the control renderer is accessed through the CurrentCell. Is there a way to access the control renderer without using the CurrentCell? Or can you think of a better way to do this?
The cleanest solution would be to assign the correct datasource based on the other columns field to style.DataSource in the QueryStyleInfo event handler.
Another idea would be to handle the CurrentCellActivating event and set the listbox just before it is displayed.
KJKen JohnsonSeptember 20, 2004 01:00 PM UTC
>The cleanest solution would be to assign the correct datasource based on the other columns field to style.DataSource in the QueryStyleInfo event handler.
We abandoned QueryCellInfo for loading dependent combobox lists because it is just too slow.
>Another idea would be to handle the CurrentCellActivating event and set the listbox just before it is displayed.
What will CurrentCellActivating get me that CurrentCellMoved doesn''t? That is where I''m currently doing what you suggest.
AdministratorSeptember 20, 2004 01:03 PM UTC
CurrentCellActivating will be called before the combobox cell is activated. It will be called for every row.
With CurrentCellMoved on the other side there is a chance that the user selects something on one row and then jumps to a cell in another row. At the time CurrentCellMoved is called you simply don''t know what the next step is for the user.
AdministratorSeptember 20, 2004 01:25 PM UTC
But isn''t the current cell required to set the DataSource, DisplayMember, and ValueMember for the combobox list? It was my understanding the CurrentCellActivating is fired before the current cell is set.
I was doing all this in CurrentCellShowingDropDown, but I discovered that a user could not utilize the AutoComplete feature since the list was not dropped.
AdministratorSeptember 20, 2004 02:02 PM UTC
At the time CurrentCellActivating is called there is no current cell and the next step will be to initialize the current cell. The EventArgs contained the row and column index of the future current cell.
So, if you set the DataSource, DisplayMember, and ValueMember at that time, the current cell initialization code should pick those values up when it gets initialzed.
Combined with a QueryCellInfo approach you could try to save those settings when CurrentCellActivating is called and then return them in QueryCellInfo.
KJKen JohnsonSeptember 21, 2004 08:41 AM UTC
Here is a small sample of what I am trying to do. Add three of four rows in the grid with the same finish but different colors. Now select all the added rows and revise all the colors to be the same. The color cell that is selected is correct, the others display the wrong value. Using QueryCellInfo is not an option for us because of how much that event slows down the application. Any insights into accomplishing a multi-select edit would be appreciated.
AdministratorSeptember 21, 2004 10:09 AM UTC
Attached find the modified sample with CurrentCellActivating caching the values and QueryCellInfo returning the cached values for the current cell. QueryCellInfo should not cause any performance penalty at all - the key is the caching.
KJKen JohnsonSeptember 21, 2004 11:37 AM UTC
Thanks for the sample Stefan. I now see what you were talking about. The only problem now is that it doesn''t solve the original problem. When I take your code and input several rows with different colors, select all the rows and revise the color only the selected row is changed. The rest of the selected rows stays the original input color.
AdministratorSeptember 21, 2004 01:02 PM UTC
Ok, I didn''t understand the part about the selected rows before ...
For that you could handle CurrentCellCloseDropDown and call CurrentCell.EndEdit so that the change is saved into the current cell.
Then you also handle CurrentCellEditingComplete and loop through the selected cells and assign the style.Text to the other cells.
KJKen JohnsonSeptember 21, 2004 03:38 PM UTC
Thanks Stefan. Your last post hooked me up.
KJKen JohnsonSeptember 23, 2004 04:36 PM UTC
Next problem. I have added a handler for the CurrentCellValidating event. Now I am getting an exception when I set the CancelEventArg Cancel property to true. If I remove the cancel property, no exception but the user can leave the screen with invalid data.
The sequence of events is:
in the CurrentCellCloseDropdown event - EndEdit is called.
in the CurrentCellValidating event - cancel property is set to true.
the exception is being thrown from the EndEdit
AdministratorSeptember 23, 2004 06:07 PM UTC
All you have to do is add the following event to your sample and you will see the exception.
private void grdList_CurrentCellValidating(object sender, CancelEventArgs e)
e.Cancel = true;
AdministratorSeptember 24, 2004 10:07 AM UTC
I added those lines but it works fine for me.
What version do you have?
Does it help if you call CancelEdit instead of EndEdit in the case that you know you want to set e.Cancel = false anyway?
AdministratorSeptember 24, 2004 10:38 AM UTC
I''ll try calling CancelEdit to see if that makes a difference. To test it, I just added the validating handler to the sample that you posted and then selected an item from a combobox list.
AdministratorSeptember 24, 2004 10:40 AM UTC
>What version do you have?
AdministratorSeptember 24, 2004 10:51 AM UTC
One problem with calling CancelEdit is the sequence in which events are executed. The CurrentCellCloseDropdown, which contains the EndEdit call is executed before the CurrentCellValidating event, where the cancel property is set. I tried calling CancelEdit in the validating property, but the EndEdit method is already called and I still get the exception.
AdministratorSeptember 24, 2004 03:01 PM UTC
What if you try to call CurrentCell.Validate() from your DropDown handler and then check the CurrentCell.IsValid property. If it is false you don''t call EndEdit.
AdministratorSeptember 24, 2004 03:43 PM UTC
Calling the current cell Validate method before EndEdit in the CloseDropDown handler did the trick.