Hi, all,
I have one grid, which have one table as DataSource
e.g. MyGrid.DataSource = MyTable
After I change some values on the Cell e.g.
Row[0].Cells["Color"] = "R", then the Row[0].Appereance.BackColor = Color.RED
It works well, in InitializeRow Event
But if I change the value, then I lost the effekt,
I have called MyGrid.Rows.Refresh(RefreshRow.ReloadData, true, true)
and MyGrid.Rows.Refresh(RefreshRow.FireInitializeRow, true, true)
but both do not work, why?
Many thanks & greetings
I don't understand your question. What do you mean when you say you "lose the effekt?"
InitializeRow will fire every time a value in the row changes. So your code needs to account for this.
Hi, Mike,
grid.datasource = myDataSet
e.g. myDataSet has be changed by database user,
and actually the grid shows the changed rows correctly,
but the effekt what I wished is the changed rows.apperance.backcolor = RED. (before that is White)
...It does not work. I have tried with ultraGrid1_CellChange , ultraGrid1_AfterRowUpdate, and ultraGrid1_AfterCellUpdate events.
but failed, these event can not be fired. what I made wrong?
Thanks
I'm still not sure I understand your question. Are you saying that row is not turning red? Or that it is?
A typical use case for the InitializeRow event is where you want to change the color of the row based on the value of a cell in that row. But what people sometimes forget is that you also may need to un-set the color when the value does not match.
So, for example, let's say you are doing this:
If e.Row.Cells["Color"] = "R" Then
e.Row.Appereance.BackColor = Color.RED
End If
This will work fine and any row whose "Color" cell is "R" will turn red. But if you then change the "Color" cell to some other value, nothing will happen. It will stay red. So the right way to do this is like so:
Else
e.Row.Appereance.ResetBackColor()
This will work better. But it's actually still pretty inefficient because it creates a new Appearance object for each row. It would be better to create a single Appearance object as part of the grid Layout's Appearance and re-use the same object.
e.Row.Appereance = e.Row.Band.Layout.Appearances("Red Appearance")
e.Row.ResetAppearance()
thanks for your posts.
very pity, still not know the reason, why the InitializeRow Event not be fired, after I change the underlying datasource..
(The Event will be fired, if I remove the changed rows then put back the same rows into dataset...)
But I find the Appearance Object is really very efficient. the only one thing is -
The Color can not be reseted (turn white) after e.Row.ResetAppearance().
for that I do need use that:
if (Convert.ToInt32(e.Row.Cells[0].Value) < 6)
else
{ e.Row.Appearance = this.ultraGrid2.DisplayLayout.Appearances["WHITE_ROW"]; } }
Certainly I should define these two Appearance Objects in MyGrid_InitializeLayout Event.
It work well, thank you very much.
Greetings