Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
110
Conditional Image in Wingrid Cell
posted

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 )

string myValue = ( string )e.Row.Cells["Priority"].Value;

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?

Can I use a Layout appearance e.g.

// e.Row.Cells["ImpactId"].Appearance = grid.DisplayLayout.Appearances["Positive"];

Cheers,
John


Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    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;
            }

     

Children