This is a migrated thread and some comments may be shown as answers.

Formatting text in Columns in a VirtualGrid

4 Answers 167 Views
VirtualGrid
This is a migrated thread and some comments may be shown as answers.
Seb
Top achievements
Rank 1
Seb asked on 17 Jun 2017, 12:15 PM

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...

 

4 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 19 Jun 2017, 07:41 AM
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.
0
Seb
Top achievements
Rank 1
answered on 19 Jun 2017, 10:42 AM

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

0
Dimitar
Telerik team
answered on 19 Jun 2017, 11:14 AM
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.
0
Seb
Top achievements
Rank 1
answered on 19 Jun 2017, 11:15 AM
Yes - this is working perfect, thanks (flagged as such - I had forgotten, sorry)
Tags
VirtualGrid
Asked by
Seb
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Seb
Top achievements
Rank 1
Share this question
or