We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Using ImageLists in GridDataBoundGrids

I have a few questions about using ImageLists in cells of a databound grid: 1. How can manually select what imageIndex to use for a cell at run time. (I.E. i want to select an image to show in a cell based off of a value in another column for that row.) 2. I would like to add an image to items that get displayed in a dropdownlist for a combocell. In this case, the value stored in the grid is an id that is mapped to another table in the database. I am getting the name of that id from the database, but I would like to display an image in the drop down based upon another column in the mapping table. (An example of what I want to do might be, a grid used for customer orders in a store. The customer can select an item he wishes to buy from a drop down. However, some items might be out of stock. I would like to display an icon showing that the item is either in stock, or is out of stock). Thank you.

3 Replies

AD Administrator Syncfusion Team August 17, 2004 07:06 PM UTC

1) You can handle the PrepareViewStyleInfo event. If e.ColIndex points to the column with the bitmap, you can set e.Style.ImageIndex to whatever value you want. If you need to get a value from another column within PrepareViewStyleInfo, then inside the If statement that you use to check the value of e.ColIndex, you can use an indexer on the grid, grid[e.RowIndex, someColIndex].CellValue, to get the value from another column. 2)Instead of a ComboBox celltype, you can use a GridListControl celltype and that will display an icon in a column. You can see a sample in this sample, Grid\Samples\CellTypes\ComboboxCells, that ships with the product. Look at the bottom of the grid in the sample.


AD Administrator Syncfusion Team August 19, 2004 11:27 AM UTC

Thanks, I was able to get #1 to work. However, I still don''t understand how the icon gets set in the dropdown. I see you are using an ArrayList of items, and each item has a property called ImageIndex, but I never see anyone getting that property. Or should I just assume that the control is doing that automagically? Does that mean I should creeate a datatable as the datasource with the columns: Display, Value, and ImageIndex? Thanks


AD Administrator Syncfusion Team August 19, 2004 12:23 PM UTC

You can do it that way adding a field to your dropdown''s data source named ImageIndex. If you do not want to do this, you can subscribe to the dropdown''s embedded grid''s PrepareViewStyleInfo event, and dynamically set e.Style.ImageIndex and e.Style.ImageList at that point based on some criteria or cache of values. Here is a little sample that uses this second technique. It also has commented out the first technique if you want to try that as well. (But don''t try using both as that might confuse things.) ComboRelations_6371.zip

Loader.
Live Chat Icon For mobile
Up arrow icon