Home Forums WinForms controls Xceed Grid for WinForms Icons in a cell

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #14542 |

    I have been looking at how to do this for weeks now and find this exceedingly complicated.

    I am simply trying to replace the content of a cell with an icon, displaying a different icon depending on the content of the cell.

    For example, if a cell contains word “Running” I would like to show a little icon of a runner, if the cell says “Paused” and icons of a ” sign.

    The examples I found so far appear very complicated, and seem to require either storage of the image in the db or otherwise difficult loading mechanism.

    Does anyone have any code snipets I could just plug-and-run (Pardon the pun) that would help me accomplish the above.

    Thanks in advance,
    Paul

    Imported from legacy forums. Posted by paullepa (had 3889 views)

    User (Old forums)
    Member
    Post count: 23064

    The best way to accomplish this is to add an unbound column, which you set the data type to bitmap, and then use this column to display the icon, while hiding the bound column. You can have a set of icons in your project folder, and you simply access these at runtime, in the AddingDataRow event.

    So in the form_load you would do something like this :

    gridControl1.AddingDataRow += new AddingDataRowEventHandler(gridControl1_AddingDataRow);
    gridControl1.Columns[ “Discontinued” ].Visible = false;

    In the event handler, do something like this :

    private void gridControl1_AddingDataRow(object sender, AddingDataRowEventArgs e)
    {
    Bitmap icon;
    if( ( bool )e.DataRow.Cells[ “Discontinued” ].Value == false )
    icon = new Bitmap( Application.StartupPath + @”\Uncheck.ico” );
    else
    icon = new Bitmap( Application.StartupPath + @”\Check.ico” );
    e.DataRow.Cells[ “column1” ].Value = icon;
    }

    Imported from legacy forums. Posted by André (had 485 views)

    User (Old forums)
    Member
    Post count: 23064

    I tried this, but when i inserted an unbound column, there was no option for dataType “Bitmap”.

    Imported from legacy forums. Posted by belay (had 305 views)

    User (Old forums)
    Member
    Post count: 23064

    This should be available : System.Drawing.Bitmap. Which version of the grid are you using?

    Imported from legacy forums. Posted by André (had 261 views)

    User (Old forums)
    Member
    Post count: 23064

    version 2.5

    thank u!

    Imported from legacy forums. Posted by belay (had 355 views)

    User (Old forums)
    Member
    Post count: 23064

    There is no reason why it should not be there. Is there any image type in the designer list? What are the types in the list?

    Imported from legacy forums. Posted by André (had 5042 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.