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; }
Mike,
I have tried this with a grid I have and it works a charm. Except for one thing.
The grid has a filter row at the top, and when using this ValueList approach for boolean values (true = tick image, false = transparent image), the filter no longer works.
The filter dropdowns DO display the image correctly, but when I select, say, the Tick image, the grid is NOT filtered by those rows with that cell having a true value. The grid instead shows no items at all. Selecting the transparent image has the same affect, no rows are displayed in the Grid.
Is there a way of working around this?
Cheers,
Mark
Hi Marleen,
The filter list does not show images from the cell by default. There's no built-in functionality to do this.
What you could do is handle the BeforeRowFilterDropDown event and loop through the items in e.ValueList and set the Appearance.Image for each one based on the DataValue of the item.
Hello,
I'm having an other problem.
In stead of using a VALUELIST I like to use the ULTRADROPDOWN with multiple columns, with the display member set to a column with the property '.Appearance.Image' set.
If I fill in the property 'value' of that column, then in the grid I see the image and the value, but in the filterrow I only see the value, not the image.
If I don't fill in the property 'value', then in the grid I only see the image (that is what I want!), but no items are added to the filterrow (only blanks,nonblanks and custom are available).
Any idea how to solve this?
Thx
Marleen
It took me some time to figure out my problem. I use v9.2.
I have to set the property Style and CellDisplayStyle to fix the problem.
UltraGrid.DisplayLayout.Bands(0).Columns("MyCol").Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Default
UltraGrid.DisplayLayout.Bands(0).Columns("MyCol").CellDisplayStyle = Infragistics.Win.UltraWinGrid.CellDisplayStyle.Default
I did a little more digging and this was fixed back in v9.1 and up, so unless you are using a very old version of the controls, you should just get the latest service release to fix the issue.
I could be wrong, but I am pretty sure this bug was fixed a while ago. What version of the grid are you using? Do you have the latest service release?
How to get the latest service release - Infragistics Community