Get formatted cell text (value)

5 posts, 0 answers
  1. Brendan
    Brendan avatar
    68 posts
    Member since:
    Dec 2011

    Posted 19 Jun 2017 Link to this post

    I have gridview with string, date, and numeric columns.  Once I set the data source and fill with data, I format each column to a suitable display - eg: short date, 2 decimal places for some, 4 decimals for others, etc. using the column.formatstring.  

    On a row click I need to get the formatted cell text, not the value and am wondering how I can do this?  Eg: the underlying value of a cell is 12345.670000 but is formatted and displayed in the cell as 12,345.67.  I could not find a "cell.text" property; and cell.value gives me the raw data.

    How can I get the formatted cell text?  Thanks, Brendan

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3708 posts

    Posted 20 Jun 2017 Link to this post

    Hello Brendan, 

    Thank you for writing.  

    You can extract the formatted text from the visual cell element. It is necessary to subscribe to the MouseDown event and get the GridDataCellElement under the mouse. Here is demonstrated a sample code snippet:
    private void radGridView1_MouseDown(object sender, MouseEventArgs e)
    {
        GridDataCellElement cellElement = this.radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridDataCellElement;
        if (cellElement != null)
        {
            RadMessageBox.Show(cellElement.Text);
        }
    }

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    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. MORDECHAI
    MORDECHAI avatar
    4 posts
    Member since:
    Feb 2019

    Posted 28 Nov 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Given the `Cell` object without any location data how can I do it?
  4. MORDECHAI
    MORDECHAI avatar
    4 posts
    Member since:
    Feb 2019

    Posted 28 Nov 2019 in reply to MORDECHAI Link to this post

    I mean 
    GridViewCellInfo
  5. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3708 posts

    Posted 29 Nov 2019 Link to this post

    Hello, 

    If you have the data cell object (GridViewCellInfo), you can find the visual cell element and get its Text property:
            private void radGridView1_CurrentCellChanged(object sender, CurrentCellChangedEventArgs e)
            {
                GridViewCellInfo dataCell = e.NewCell;
                GridRowElement visualRowElement = this.radGridView1.TableElement.GetRowElement(dataCell.RowInfo);
                if (visualRowElement != null && visualRowElement.VisualCells.Count > 0)
                {
                    string formattedText = visualRowElement.VisualCells[dataCell.ColumnInfo.Index].Text;
                    RadMessageBox.Show(formattedText);
                }
            }
    I hope this information helps. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top