I'm having an issue where when a user clicks any cell of an active (and selected) row, all cells above the active row are also selected. Instead of only the chosen cell being selected.
This behavior only occurs when the active row was set without the grid having focus. I've verified if set focus on the grid as I select the row the issue goes away, but in this instance I'd prefer not to change the current focus.
From some other posts I tried playing around with something like the following:
this.Grid.DisplayLayout.Override.SelectTypeCell = SelectType.Single;
With this selection mode on cells the issue lessens, but still occurs. Instead of all cells from the top of the grid to current row being selected, only the top most row (not counting column headers) and the desired cell are selected. Using SelectType.None appears to fix the issue and give desired behavior (single cell selection) but there's concern users may not be able to select and edit a cell (so far I've not experienced this in my dev environment).
Anyone else run into this and found a better fix than changing focus? Or is it expected that with SelectTypeCell = SelectType.None that a single cell in the grid can still be selected and edited?
Thanks,
Chad
ChadMarshall said:there's nothing quite like recreating grid rows happening
But that is what's happening. When you click on the detail grid, the summary grid is changing rows for some reason. This re-binds the detail grid which means it throws away all the rows and creates new ones based on the new active row in the summary grid. So what I describes is exactly what is happening.
I was wrong about the detail grid refreshing itself with the same rows it already had. It is apparently refreshing itself with a completely different set of rows. But the problem is essentially the same.
Thanks for your help. Although there's nothing quite like recreating grid rows happening, in working through your suggestions I did finally stumble across a missing piece of information. From a visual perspective, it all seems so obvious now :)
In the screen shots I posted, if you notice in the second pic the summary control on the left has a different row selected than in the first picture. I was so focused on the detail grid changing, this went unnoticed. Of course, once the summary grid changes rows it auto changes rows in the detail grid. More or less there's a circular reference here I need to track down and fix, or at least make sure the proper indexes are being passed around so the rows quit changing.
Although this doesn't completely explain why setting focus on the detail grid fixes the issue, at least I have enough understanding now that it's not an Infra issue. Again, thanks for the help.
Hi,
It's tough to see what's going on here since there are so many colors.
In your first screen shot, it looks like the first cell in the row of the second grid is the active cell and the rest of the row is the active row.
In the second screen shot, the active Row appears to be the first row, but I don't really know what's going on with the cells in the Amount column. I guess you must be applying some selected appearances and those cells are selected. You could verify that by checking the grid.Selected.Cells.Count at this point.
But whatever is happening here, I've never seen anything in the grid that would cause this. My first guess is that something in your code is causing the active row to change. In fact, now that I think about it, it makes sense, because if something in your code is changing the ActiveRow in the grid or even better causing the grid to recreate the rows then the click might be occurring on different UIElements.
So maybe the grid gets a MouseDown message on the CellUIElement you cilcked and then something in your code is causing a reset notification from the data source, which causes the grid to re-create all of the UIElements for every row and then the grid gets a MouseUp and at that point, a different element is now under the mouse.
The more I think about this, the more sense it makes, because the grid could easily be re-using the UIElement you clicked on for the same column in the first row. So that element gets a MouseDown and then is reused at the top of the grid and then the cell in the row you clicked gets a MouseUp, so it acts like a drag selection.
Check your code for event handlers in the grid's MouseDown, Enter, or GotFocus events - or maybe for LostFocus or Leave events on the first grid.
Without a video or sample code this one may be too tough to explain. I've attached some screen shots from me re-creating the issue locally.
The first picture shows the two UltraGrid objects and how clicking in one activates a row in the second. Keep in mind the second UltraGrid does not receive focus at this time. Focus would still be in the first grid since that's where the user clicked.
The second picture shows what happens after clicking one time on the active row of the second grid. The same thing happens regardless of which cell is clicked, I just chose one that would give the best visual in the screen shot.
I took a quick stab at sample code last week, but I wasn't able to reproduce the bad behavior. As time permits I'll try to bring in some more complexity from our main app to the sample app to either help me figure out whats wrong, or give you guys some code to look at. For now I'm just using the .Focus() fix making this less of a priority for me to address.
Hi Chad,
I'm having a little trouble following you since the setup is so complex. But it sounds to me like you may be mixing up selected and active.
The ActiveRow in the grid is the current row that has input focus. By default, the grid syncrhronizes this row with the current row in the BindingManager/CurrencyManager.
Selecting is completely different. Selected indicates rows, cells, or columns that are highlight by the user.
There can only ever be one active row, but you can (depending on the SelectTypeRow, SelectTypeCell, and SelectTypeCol properties) have multiple selected rows.
By default, when you place a new WinGrid on a form, it applies an appearance to the active row and the active cell to make it look like a selected row.
So if you are seeing a row in the grid that looks selected, but is not actually selected and does not exist in the grid.Selected.Rows collection, it's most likely the ActiveRow.
Here's a KB article that explains how to turn off these ActiveRow/ActiveCell appearances:
FAQ:How do I turn off the ActiveRowAppearance so that the active row in the grid does not appear selected.