Hi there,
I'm looking for some advise on getting an image into my wingrid cell correctly. I have tried a few different things with some strange results, most likely I'm missing the point somewhere along the lines...
OK I have a grid (always a good start), a column called priority (with values like high, medium, low etc). When the grid row is initialised I find the priority cell's value. If the cell is high I want to replace the text in the cell from the word "high" to an exclaimation mark image (16x16 png).
So...
public void gridTasks_InitializeRow( sender,... e )
if ( myValue.ToLower() == "high" )
{e.Row.Band.Columns["Priority"].CellAppearance.Image = Icons.exclaimation_red;//e.Row.Band.Columns["Priority"].CellAppearance.ImageBackground = Icons.exclaimation_red;
e.Row.Band.Columns["Priority"].CellDisplayStyle = CellDisplayStyle.FullEditorDisplay;//e.Row.Band.Columns["Priority"].CellButtonAppearance.Image = Icons.exclaimation_red;
e.Row.Cells["Priority"].Value = "";}What's really strange is I can step through the debugger and see myValue is "high", every 3rd or 4th row but every row comes back with the priority column cell with the image in it. I don't think this is the best way of applying the image to a cell so is there a better way?
// e.Row.Cells["ImpactId"].Appearance = grid.DisplayLayout.Appearances["Positive"];
Cheers,John
Hi John,
The code you have here won't work right, because you are setting the Value on the cell. The problem with this is that the InitializeRow event might fire again for the same row and the value will have been lost. So you don't want to do that.
There are a number of ways you can go here, but I would probably use a ValueList. What you do is use the InitializeLayout event of the grid and create a ValueList. Personally, I would probably use an enum for the value of the cell, rather than a string. But either way, the basic approach is the same. It looks something like this:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { // Create a ValueList with an image for each item. ValueList priorityList = e.Layout.ValueLists.Add("Priorities"); ValueListItem vli = priorityList.ValueListItems.Add("high"); vli.Appearance.Image = DummyDataCreator.GetTextBitmap("H"); vli = priorityList.ValueListItems.Add("medium"); vli.Appearance.Image = DummyDataCreator.GetTextBitmap("M"); vli = priorityList.ValueListItems.Add("low"); vli.Appearance.Image = DummyDataCreator.GetTextBitmap("L"); // Set the DisplayStyle to Picture so that the list displays only pictures, // and no text. priorityList.DisplayStyle = ValueListDisplayStyle.Picture; // Assign the ValueList to the column e.Layout.Bands[0].Columns["String 1"].ValueList = priorityList; // Don't allow editing. e.Layout.Bands[0].Columns["String 1"].CellActivation = Activation.NoEdit; }
Hi Mike,
I am experimenting with this code, but I am unable to get the image to show. Even the "Y"/"N" values show correctly in the grid, but the image will not. I am trying everything to get the image to show, even setting the image via CellAppearance.Image for the entire column and I am unable to get the images to show.
Dim hazardousImages As ValueList = e.Layout.ValueLists.Add("Hazardous") Dim vli As ValueListItem = hazardousImages.ValueListItems.Add(True, "Y") vli.Appearance.Image = My.Resources.hazmat vli = hazardousImages.ValueListItems.Add(False, "N") vli.Appearance.Image = Nothing
hazardousImages.DisplayStyle = ValueListDisplayStyle.Picture e.Layout.Bands(0).Columns("Hazardous").ValueList = hazardousImages e.Layout.Bands(0).Columns("Hazardous").CellActivation = Activation.NoEdit
' Create a ValueList with an image for each item. Dim teamImages As ValueList = e.Layout.ValueLists.Add("Team") vli = hazardousImages.ValueListItems.Add(True, "Y") vli.Appearance.Image = My.Resources.users2 vli = teamImages.ValueListItems.Add(False, "N") vli.Appearance.Image = Nothing
hazardousImages.DisplayStyle = ValueListDisplayStyle.Picture e.Layout.Bands(0).Columns("Team").ValueList = teamImages e.Layout.Bands(0).Columns("Team").CellActivation = Activation.NoEdit
We have also tried using a Infragistics.Win.ConditionValueAppearance and setting it to the ValueBasedAppearance for the column. In this case, we have the same results. Everything works except the image.
Dim trueCond As Infragistics.Win.ICondition = CType(New Infragistics.Win.OperatorCondition(Infragistics.Win.ConditionOperator.Equals, True), Infragistics.Win.ICondition) Dim falseCond As Infragistics.Win.ICondition = CType(New Infragistics.Win.OperatorCondition(Infragistics.Win.ConditionOperator.Equals, False), Infragistics.Win.ICondition)
Dim trueApp As New Infragistics.Win.Appearance Dim falseApp As New Infragistics.Win.Appearance
With trueApp .Image = My.Resources.hazmat .ImageVAlign = Infragistics.Win.VAlign.Middle .ImageHAlign = Infragistics.Win.HAlign.Left .BackColor = Color.Blue End With With falseApp .Image = My.Resources.users2 .ImageVAlign = Infragistics.Win.VAlign.Middle .ImageHAlign = Infragistics.Win.HAlign.Left End With
e.Layout.Bands(0).Columns("Hazardous").ValueBasedAppearance = New Infragistics.Win.ConditionValueAppearance(New Infragistics.Win.ICondition() {trueCond, falseCond}, New Infragistics.Win.Appearance() {trueApp, falseApp})
Thanks for your help.
Hi,
I tried this out using the same code you provided here and it's working fine for me. So my only guess is that there is something in your code that occurs after this code which is blowing away these settings. Maybe you are loading a layout into the grid after this code is executed?
I'm attaching my sample project here so you can try it on your machine just to be sure it's not a bug in you version of NetAdvantage.
Thanks! I have resolved this issue. Being my first time to post on the forum, I didn't know whether this old thread would be the correct place to post my question, so I had also made a new thread at http://es.infragistics.com/community/forums/p/89937/444297.aspx where I will continue with an additional question.