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
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
Thanks Mike,
That works great. I had some trouble with it originally, it must have been some setting in the grid because the image wouldn't appear at all.
I deleted the grid and re-applied it, bingo.
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; }