I have an UltraWinGrid that is bound to a datasource. I set the grid to group the contents by a key value. I want my users to be able to add an extra row to the group they have currently selected.
This is no problem when they have a row selected as I am able to use the ActiveRow property then to determine the keyvalue that I need. The problem I am having is that the user can also select the headers of the groups and thus have no ActiveRow. I need to be able to read the keyvalue of the group that the user has selected to be able to add a new row to my collection, so that it can be placed in the correct group afterwards.
Is there a way to determine which group/band the user has selected if they have no actual row selected in the grid, but only the header?
Thanks Mike,
that was exactly what I was looking for. I managed to solve my problem with this.
I think by "header", you are probably referring to the GroupByRow, not the column headers.
If a GroupByRow is selected/active, then the grid's ActiveRow will return that GroupByRow, it will not be null.
Its not clear to me what row you are trying to get to, though. You can determine the value that the group is grouped by. To do that, you would cast the row into a UltraGridGroupbyRowand check it's Value property.
If you are trying to get to a value of one of the child rows of a particular GroupByRow, then once again you must cast the row into the UltraGridGroupbyRow and then use the Rows collection of that row. Keep in mind that it's possible to have mulitple levels of grouping. So the child rows of a GroupByRow may also be GroupByRows, in which case, you can just keep walking down the tree until you get to a real row.
There are properties on the row called IsDataRow and IsGroupByRow, so you can check what type of row you are dealing with before you try to cast it.
This code does not seem to work. When the only the header is selected all the items in the ultraGrid.Selected are empty (cells, columns and rows).
To clarify: by header I mean the line above the column headers that gets created when items are groups. Per default it contains the name of the property that is being grouped by, the value of the property and the amount of items in the group. For example: UserID: 12 (4 items).
When that header is clicked I need to know the value of UserID of that group. Reading it from the caption won't be an option as I will modify that to say something different in my final version of my program.
SelectedColsCollection selectedCols = this.ultraGrid.Selected.Columns;UltraGridColumn col = selectedCols.Count > 0 ? selectedCols[0].Column : null;UltraGridGroup group = col != null ? col.Group : null;if ( group != null && group.Header.Selected ){ UltraGridBand band = group.Band;}
I can't remember if the grid allows columns from different bands to be selected concurrently (I don't think it does) ; if it does, you would have to do something like handle AfterSelectChange and execute this code in response to that event, then cache the UltraGridBand reference so that you always have the most recently selected one.