Hi guys.
I have a datagrid with 2 bands, and a select button on the first band. Everytime user clicks on the button, I use ClickCellButton to detect which row index was clicked.
When returning with selected result, I will bind the result in the datagrid. At this time, I need to change the BackColor of the row from first band that was clicked. But unfortunately, the BackColor only can be changed start from index 1. Meaning if the index is 0, the BackColor of it still remain the same.
Below is my codes, please advise.
In CellClickButton event
ActiveRowIndex = dgRawMat.ActiveRow.Index
In InitializeRow event
If e.Row.Band.Index = 0 Then If e.Row.Index = ActiveRowIndex Then e.Row.Appearance.BackColor = Color.Green e.Row.Appearance.BackColor2 = Color.DarkSeaGreen End IfEnd If
The row is probably not selected, it's most likely the Active row. This happens because the grid synchronizes it's ActiveRow with the current position of the BindingManager.
You can turn this off by setting SyncWithCurrencyManager to false on the grid, but that has other implications.
Another option would be for you to turn off the ActiveRowAppearance on the grid.
FAQ:How do I turn off the ActiveRowAppearance so that the active row in the grid does not appear selected.
Hi Mike.
I got the issue solved. The backcolor on the first role was indeed updated, just that the row was selected by default after data binding, so the backcolor was light yellow.
Is there anyway to avoid the default select?
I'm sorry, but I just don't understand what you are trying to do here.
You can highlight a row using colors in the InitializeRow event. You can select rows to highlight them using the grid.Selected.Rows collection.
If you want to trap when a row is expanded, use the Before/AfterRowExpanded events.
The dialog will add a new row to the grid under Onion.
You suggestion only work when there is something changes in the grid. I need to highlight the root band if user click on the expand sign.
Please help.
Hi,
Let me see if I have this right...
So your root band is a list of ingredients and the user needs to pick more specific types of each one? Is that right?
So the user clicks on a button in the Onion row in the first band and you show a dialog. Now you are showing a dialog and the dialog does what exactly? Is this dialog adding a new row to the grid under Onion? Or do you mean that you are adding a row to some other grid? Or just changing some field in the Onion row?
If you want to apply some sort of highlight or color to any row in the grid then the InitializeRow event is usually a good place to do it. But the event only fires when something in that row changes. So if you want to change the appearance of a row based on something other than a value in that same row, then you will either have to set the appearance on the row in some other event or else you will have to force InitializeRow to re-fire for that row.
Personally, I prefer the latter method, because that way the row appearance is still based on some field or property of the row. To make the InitializeRow event fire, you can so something like this:
this.ultraGrid1.Rows.Refresh(FireInitializeRow);