formating wrong if grid is scrolled

3 posts, 1 answers
  1. Mathias
    Mathias avatar
    2 posts
    Member since:
    Jun 2014

    Posted 22 May 2015 Link to this post

    I used the Grid in the Telerik samples for WinUI C:\Program Files (x86)\Telerik\UI for WinForms Q1 2015\Examples\QuickStart\GridView\Rows\AddNewRow\Form1.cs and added the following code to get the UnitPrice in a blue font:

     

     public Form1()
    {
    ...
    this.radGridView1.CellFormatting += new CellFormattingEventHandler(radGridView1_CellFormatting);
    }

    void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
    GridDataCellElement dataCell = e.CellElement as GridDataCellElement;
    if (dataCell != null)
    {
    if (dataCell.ColumnInfo.Name.ToLower() == "unitprice")
    {
    dataCell.ForeColor = System.Drawing.Color.Blue;
    dataCell.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0);
    }
    }
    }

    This works when the form get first loaded, but if I scroll the grid other cells also get blue randomly. 

     

    Is there something I can do about this?

     Mat

     

  2. Answer
    Dess
    Admin
    Dess avatar
    1601 posts

    Posted 22 May 2015 Link to this post

    Hello Mat,

    Thank you for writing.

    Due to the UI virtualization in RadGridView, cell elements are created only for currently visible cells and are being reused during operations like scrolling, filtering, grouping and so on. In order to prevent applying the formatting to other columns' cell elements (because of the cell reuse) all customization should be reset for the rest of the cell elements. Please refer to our Formatting Cells help article.

    I hope this information helps. Should you have further questions, I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mathias
    Mathias avatar
    2 posts
    Member since:
    Jun 2014

    Posted 22 May 2015 in reply to Dess Link to this post

    Works now. 

     

    Thnak you.

     

    Mat

Back to Top