Apologies if this has been answered previously, my search didn't turn up anything.
Here's my situation. Inside of a wingrid column (bound datatype is of type decimal), I'm in need of having the ability to conditionally show an image, image + text, or just text all within the same column *while still maintaining the ability to access the cell's bound decimal value via the value property*.
I can successfully show text or text + image (i simply set the image property on the cell's appearance and left justify the image while right justifying the value). What I can't find is a good way to ONLY show the image (again while still maintaining the cell's decimal value).
Approaches I have tried:
1) For that cell only, set the cell's forecolor to the backcolor. Works except that I ran into issues with coloring the selection colors as well and in the end found this approach too cumbersome.
2) Use a drawfilter to intercept the drawing of that cell's forecolor. Because we use our own custom editors for cells, it proved difficult to find the correct component to intercept on draw.
Both 1&2 could probably be made to work but feel like a *lot* more work than is probably necessary to solve the problem. Is there an easier solution I'm overlooking.
Christopher Rowland
How to get and display image in grid from the DataBase?
Try:
grid.DisplayLayout.UIElement.DirtyChildElements(true);
I think that should do it. If not, try:
grid.Refresh();
If neither of those works alone, try both. :)
Thanks Mike. I'm already using a CreationFilter for an unrelated reason so it was simple to hook into the CellUIElement creation and add the code you suggested. It seems to work well.
The only issue I have with it now is that the application of the image in the cell can potentially happen after the grid has already been drawn and displayed. As a result the cell's child elements have already been drawn. Scrolling these rows off the visible area and scrolling them back causes them to be redrawn correctly.
What would be the most correct way to "redraw" the grid (and thus use the creation filter logic) after the user has selected "show image only" so that existing cells will draw like I want them?
Thanks
Hi Christopher,
puckstopper_37 said:1) For that cell only, set the cell's forecolor to the backcolor. Works except that I ran into issues with coloring the selection colors as well and in the end found this approach too cumbersome.
This is probably not a good solution, because the user could stil highlight the text, even if that can't see it. Also, the text might be visible when the row or column is highlighted.
puckstopper_37 said:2) Use a drawfilter to intercept the drawing of that cell's forecolor. Because we use our own custom editors for cells, it proved difficult to find the correct component to intercept on draw.
I think this solution is more in the right direction, but I would use a CreationFilter rather than a DrawFilter. The CreationFilter allows you to prevent the CellUIElement from creating it's normal child elements and replace those elements with whatever element(s) you like.
In this case, what you would do is handle the BeforeCreateChildElement method of the CreationFilter and trap when the parent is a CellUIElement. From there, you can get the cell and decide if you want this cell to only display an image. If so, what you do is create an ImageUIElement, set the Image and the Rect on this element, add it to the CellUIElement's ChildElements collection and return true from BeforeCreateChildElement to tell it that the operation is complete and not to create it's normal child elements.