Formatting text in Columns in a VirtualGrid

5 posts, 1 answers
  1. Seb
    Seb avatar
    3 posts
    Member since:
    Mar 2017

    Posted 17 Jun Link to this post

    Hi,

     

    I am utterly confused by my inability to format numbers in a VirtualGrid to only show three decimals. I can find no access to a "Columns" property, and when using the CellFormatting event, I am unable to utilize CellElement.FormatString (VS tells me the set accessor is inaccessible in that context)...

     

    How can I prevent numbers from showing as 1.23456489456987654 and instead show 1.235 (for instance), without converting the underlying data itself?

     

    Any help appreciated, because I am convinced this must be a trivial operation, which got me to search for hours - to no avail.

     

    For reference, here is what I was trying with the CellFormatting event that will not compile for me:

     

           private void rvgData_CellFormatting(object sender, VirtualGridCellElementEventArgs e)
            {
                if (e.CellElement.RowIndex > -1)
                {
                    if (e.CellElement.ColumnIndex > 1)
                    {

    /* This yields: Error    CS0272    The property or indexer
    'VirtualGridCellElement.FormatString' cannot be used in this context
    because the set accessor is inaccessible */
                        e.CellElement.FormatString = "...";
                    }
                }
            }

     

    And there's for something else that's frustrating: your code editor on this site does not seem to work on Firefox/Mac...

     

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    1877 posts

    Posted 19 Jun Link to this post

    Hi Seb,

    RadVirtualGrid does not keep any data locally. It requests only the currently visible values at runtime. This is why you cannot access column information and set the format string. You approach is correct and you should use the formatting event. Just set the text of the cell:
    private void RadVirtualGrid1_CellFormatting(object sender, VirtualGridCellElementEventArgs e)
    {
        if (e.CellElement.RowIndex > -1)
        {
            if (e.CellElement.ColumnIndex > 1)
            {
                
                e.CellElement.Text =  string.Format("{0:#,0.000}", (double)e.CellElement.Value);
            }
        }
    }

    I am not sure which code editor you are pointing at. Cous you please specify that?

    I am looking forward to your reply.
     
    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Seb
    Seb avatar
    3 posts
    Member since:
    Mar 2017

    Posted 19 Jun Link to this post

    Dimitar,

    Thank you! Of course it was right in front of my nose... I might argue the object model isn't exactly very intuitive when you have a property that seems to be available but isn't, but all I care about is the solution and this does it - I appreciate your help!

     

    On the code editor - I'm using the "Formatting Code Block" option in the "Formatting Options" section of the forum post. The popup gets half cropped on Firefox (see attachment). I realized today the OK/Cancel buttons were there, but yesterday they weren't and/or, by hacking with the developer tools so I could see the entiire popup (instead of the cropped version you see on the screenshot), the buttons disappeared?

    Hope this helps,

     

    Seb

  4. Dimitar
    Admin
    Dimitar avatar
    1877 posts

    Posted 19 Jun Link to this post

    Hi Seb,

    I am glad that this is working fine now. We will check the case with the code editor form.

    Do not hesitate to contact us if you have other questions.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Seb
    Seb avatar
    3 posts
    Member since:
    Mar 2017

    Posted 19 Jun in reply to Dimitar Link to this post

    Yes - this is working perfect, thanks (flagged as such - I had forgotten, sorry)
Back to Top