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
630
Cell level format
posted

Hi

Is there a cell level property using which i can apply formats to a value for a particular cell?

I have grid(dynamic grid using ultradatasource) such that there are predefined formats(e.g. percentage,currency etc) to be applied to values for some cells within a column.

In the forums i can find ways to apply format for a complete column but that is not useful in my case.

Normal 0 false false false EN-US X-NONE X-NONE

 

TYPE

VALUE

a

<dollar>

b

<percentage>

 

  • 69832
    Offline posted

    The best way to solve this problem is to use a DefaultEditorOwner when you create the editor that you assign to the UltraGridColumn.Editor property. This class derives from the class that we use to abstract out the communication layer between the editor and the grid. In your case you would derive a class from DefaultEditorOwner, override the GetFormat method, and pass an instance this derived class into the constructor of the editor you assign to the UltraGridColumn.Editor property.

    The signature of the GetFormat method (like most of the virtual methods exposed by this class) contains an 'ownerContext' parameter; this is either the UltraGridCell or a CellUIElement, and if I remember, can also be an UltraGridRow as well, although you can ignore that case and just call the base class implementation. Once you get a context of a cell, you decide what format you want to apply, then assign that format to the out parameter of the same name. In this manner, you can apply a different format to each cell in that column dynamically.

    • 630
      posted in reply to Brian Fallon

      Can you please provide a simple code example for that(vb.net)?

      Thanks

      • 630
        posted in reply to Mike Saltzman

        Hi

        Thanks for your example but there was no effect when i used it in my project. Any idea why?

        Just to make my case clear I am looking for a simple cell level property to format a cell's value,isn't there anything like that in Wingrid?

        And one more thing the cellchange event is taking a lot of time.It is getting executed while editing also. And  using AfterCellChange event is taking even more time.

        Is there  a best practice to use these events?

         

        Thanks

         

         

         

        • 469350
          Offline posted in reply to Anandha

          Hi,

          grakgem said:
          Thanks for your example but there was no effect when i used it in my project. Any idea why?

          The only reason I can think of why this would not work is if you are using a very old version of the controls. Perhaps there's a bug in an older version or maybe the Format on the editor was not supported in some older version and was added later.

          grakgem said:
          Just to make my case clear I am looking for a simple cell level property to format a cell's value,isn't there anything like that in Wingrid?

          No, the Format property is on the column, there's no Format property on the Cell, so you have to use an editor. If the field you are working with is read-only and the user cannot edit it, then another option to consider would be to use a CreationFilter and format the text of the UIElement directly. So this would affect the display without affecting the actual value of the cell.

          grakgem said:

          And one more thing the cellchange event is taking a lot of time.It is getting executed while editing also. And  using AfterCellChange event is taking even more time.

          Is there  a best practice to use these events?

          CellChange fires on every keystroke. There is no AfterCellChange event, so I'm not sure which event you mean. AfterCellUpdate, maybe? That event only fires once when the cell edit is committed to the underlying DataSource of the grid. I can't see any reason why either of those events should be taking a lot of time, unless maybe something in the code is causing an exception and you are catching and handling it so you don't see the message.

           

          • 630
            posted in reply to Mike Saltzman

            Mike Saltzman"]The only reason I can think of why this would not work is if you are using a very old version of the controls. Perhaps there's a bug in an older version or maybe the Format on the editor was not supported in some older version and was added later.

            we are using ver. 8.3.20083.1009.Does it support this feature?

            • 469350
              Offline posted in reply to Anandha

              I just took a look and it looks like I was wrong and this always worked.

              But I noticed that the Format and the FormatInfo properties on the column will override the properties on the editor. So be sure you are not setting these properties on the column.

              If that still doesn't help, see if you can duplicate the problem in a small sample project and post it here (you can attach a file under the Options tab) and I will be happy to take a look and see why it's not working.

              • 630
                posted in reply to Mike Saltzman

                Hi

                We are not setting the format property at column level.

                As we have to apply different formats to different cells,whose row index and column index are dynamically generated,we have created a function using your example which will be called every time we are changing the value of a cell & used the code written in "InitializeRow" event of your example.

                But still its not working.Any suggestion?

                Thanks