Ok, this has been driving me crackers for a couple of hours now. I'm a newbie to UltraGrid
I have a databound UltraGrid. I added an extra column with an icon and text in it with the following:-
private void ugrBlah_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e){ // Add new column for padlock (if it's not already there) if (!e.Layout.Bands[0].Columns.Contains("IsLocked")) e.Layout.Bands[0].Columns.Add("IsLocked", "Locked");}private void ugrBlah_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e){ e.Row.Cells["IsLocked"].Appearance.Image = Properties.Resources.padlock; e.Row.Cells["IsLocked"].Value = "Cheese";}
Which works fine... I get a nice padlock icon with "Cheese" next to it. Padlocked cheese.
But then, in response to a button click, I want the currently selected / lit / active row to change icon and text. I've tried the following:-
ugrBlah.ActiveRow.Cells["IsLocked"].Value = "Cake";ugrBlah.ActiveRow.Cells["IsLocked"].Appearance.Image = Properties.Resources.padlock_open;
It changes the icon, but not the text Value.
I have tried ...ActiveRow.Update(), and ugrBlah.Refresh(), both to no avail.
Any ideas anybody?
Are you sure that the row that you're trying to change is the active row? Are you clicking a button in a grid column, or is it a button outside of the grid? The following code worked for me:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e){ UltraGridColumn col = e.Layout.Bands[0].Columns.Add("Button"); col.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button; col = e.Layout.Bands[0].Columns.Add("Food"); }private void ultraGrid1_ClickCellButton(object sender, CellEventArgs e){ e.Cell.Row.Cells["Food"].Value = "The cake is a lie"; e.Cell.Row.Cells["Food"].Appearance.Image = Image.FromFile("images.jpg");}private void button1_Click(object sender, EventArgs e){ this.ultraGrid1.ActiveRow.Cells["Food"].Value = "The cake is a lie"; this.ultraGrid1.ActiveRow.Cells["Food"].Appearance.Image = Image.FromFile("images.jpg");}
The code worked for both a cell button and grid button. It's possible the row is selected, but not active. If you're positive it's the correct row and it's active, I'm not sure what's going on; perhaps you should make sure you have the latest hotfix.
-Matt
Hi Matt,
Thanks for the reply.
Where would the hotfixes be? I can't see them on the Infragistics "Download" page.
I've checked, and indeed the row is Activated. In fact I'm using...
ugrBookmarkedAssemblies.ActiveRow.Cells["IsLocked"].Appearance.Image = Properties.Resources.padlock;
... thus using the "ActiveRow", and the image changes as expected.
And if i look in debugger at ugrBookmarkedAssemblies.ActiveRow.Cells.All[5].Activated (5 being the index into the added column), its set as true.
Then i do...
ugrBookmarkedAssemblies.ActiveRow.Cells["IsLocked"].Value = "RRRRR";
... changes...
ugrBookmarkedAssemblies.ActiveRow.Cells["IsLocked"].OriginalValue
to "RRRRR"... but not .Value, or .Text.
Prefixing the code block with
ugrBookmarkedAssemblies.ActiveRow.Cells["IsLocked"].Activate();
and / or appending with
ugrBookmarkedAssemblies.ActiveRow.Update();
doesn't seem to make any difference either :(.
If you're using 8.1, I don't think there has been a hotfix released yet as it would appear in the downloads section.
Unfortunately, I'm not really sure what's going on without seeing it in action. Do you have any event handlers that would somehow prevent this text from changing? A DataFilter? You should probably submit this to developer support.
Ahhh...
I have an InitializeRow event. I thought this was only used as the grid is initializing each row, therefore put default values into it... but... it's firing after i change the .Value with the button click.
d'uh.
I think I did see that and try it... but for some reason it was always true, probably due to my lack of understanding of when the events fired...
I've just tried it now, instead of checking the new column for null values, and the e.ReInitialize seems to be working fine :).
You can check e.ReInitialize in InitializeRow to determine if the row is being initialized the first time or a subsequent time.