We have bound a grid to a datatable object. One of the columns in the table is a business object.
What we want to do is have the cell display an image in the cell (without text), but when outlook grouping is turned on, we want the header to include the image and the text.
We have been able to accomplish this by:
additionally, we have written IComparer class to allow sorting and grouping to work.
What we would really like is to be able to get the grid to better understand the object, so that it would know what method to call to get what is to be displayed in the cell and how to format a group-by line so that we can put this in the object and use it everywhere rather than having to clone the InitializeRow and InitializeGroupByRow event code and any other form-specific code that will be required.
Can anyone shed some light onto how we could enhance our business objects to work better with the grid (and other controls, for that matter) so that we can minimize the amount of special code simply to display the object? Are there any methods the grid calls to get the contents of an object other than ToString() when dealing with a "non-standard" data type?
Thanks,
dana
Thanks, this is exactly the type of direction I was looking for.
Dana
Hi Dana,
You could control the text that the grid displays for this object in a couple of ways. One is to use the ToString() method like you are doing. Another is to use a DataFilter in the grid.
There's nothing you could put on the object itself that would allow the grid to interpret an image from it, though. I'm afraid you would have to code that yourself.
If you wanted to make the code more generic, though, you might be better off using a DrawFilter or a CreationFilter. The CreationFilter, for example, could trap for the creation of a CellUIElement in a column whose DataType is the type of your custom object. Then you could modify the cell and shift the TextUIElement over and add an ImageUIElement. If you coded this CreationFilter correctly, you could then simply set the CreationFilter property of any grid you want to an instance of the CreationFilter and you wouldn't have to duplicate the same code in multiple grids.
If you are not familiar with CreationFilters, I recommend checking the Infragistics KnowledgeBase for articles and samples. Also, get the UIElementViewer utility. It's invaluable when working with this sort of thing. Introducing the Infragistics UIElementViewer Utility