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

formating wrong if grid is scrolled

2 Answers 26 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mathias
Top achievements
Rank 1
Mathias asked on 22 May 2015, 03:12 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 May 2015, 03:31 PM
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
0
Mathias
Top achievements
Rank 1
answered on 22 May 2015, 03:56 PM

Works now. 

 

Thnak you.

 

Mat

Tags
GridView
Asked by
Mathias
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Mathias
Top achievements
Rank 1
Share this question
or