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
1105
Show image and value in grid cell
posted

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

 

 

Parents
  • 469350
    Suggested Answer
    Offline posted

    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.

Reply Children