Hi,
I am facing a problem in cell formatting event of my radGridView. Formating cell in this event is making my Grid's scrolling very slow, is there any event that I can use instead of cell formatting that would fire each time after grid bind as cell formatting fires each time after I scroll my grid, and this is making my scrolling slow.
Or is there any other way in which i can change the value of my cell.
Regards,
Shweta Garg
5 Answers, 1 is accepted
0
erwin
Top achievements
Rank 1
Veteran
Iron
answered on 13 Oct 2008, 02:17 PM
In similar situations, I try to minimize the amount of code that's running in the CellFormatting event handler. For example, I do load all required data into efficient structures such as Dictionarys before showing the grid.
I guess there's not much else you can do, because formatting cells "in advance" would be against the philosophy of formatting just what is required and make the Cell Formatting event useless.
Regards
Erwin
I guess there's not much else you can do, because formatting cells "in advance" would be against the philosophy of formatting just what is required and make the Cell Formatting event useless.
Regards
Erwin
0
Shweta
Top achievements
Rank 1
answered on 14 Oct 2008, 05:06 AM
Is there any event which fires each time after the grid is binded..?
0
Hi guys.
Erwin, thank you for your comments, you are absolutely correct.
It is a bad practice to change the cell value in the CellFormatting event. This event is called after the cell value has been updated and when the cell needs to change its visual state.
You could use the DataBindingComplete event for this purpose. Take a look at the code snippet below:
Another option is to use RadGridView in virtual mode. In this case you should specify the columns and the rows and set the VirtualMode property to true. You should also process the CellValueNeeded event to set the desired cell value:
Check the "high refresh" sample from the QSF for more information on the virtual mode.
I hope this helps. Should you have any other questions, do not hesitate to contact us.
Greetings,
Jack
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Erwin, thank you for your comments, you are absolutely correct.
It is a bad practice to change the cell value in the CellFormatting event. This event is called after the cell value has been updated and when the cell needs to change its visual state.
You could use the DataBindingComplete event for this purpose. Take a look at the code snippet below:
void radGridView1_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e) |
{ |
this.radGridView1.GridElement.BeginUpdate(); |
foreach (GridViewRowInfo row in this.radGridView1.Rows) |
{ |
row.Cells["Value"].Value = 10; |
} |
this.radGridView1.GridElement.EndUpdate(); |
} |
Another option is to use RadGridView in virtual mode. In this case you should specify the columns and the rows and set the VirtualMode property to true. You should also process the CellValueNeeded event to set the desired cell value:
this.radGridView1.ColumnCount = 1; |
this.radGridView1.RowCount = 4; |
this.radGridView1.VirtualMode = true; |
void radGridView1_CellValueNeeded(object sender, GridViewCellValueEventArgs e) |
{ |
e.Value = "" + e.RowIndex + ";" + e.ColumnIndex; |
} |
Check the "high refresh" sample from the QSF for more information on the virtual mode.
I hope this helps. Should you have any other questions, do not hesitate to contact us.
Greetings,
Jack
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Shweta
Top achievements
Rank 1
answered on 15 Oct 2008, 08:02 AM
Hi,
Thanks for replying Erwin and Jack..
The thing in these two events is none of the event fires each time after the data bind.
Let me tell you my exact prob:
I have a image column in which i have to show an image based on the value in my another column that is hidded in the grid.
Lets say i have a hidden column 'Notes', if there is a value in this column then i have to show a image in the corresponding image cell otherewise the respective image cell would be blank.
And so, I will have to bind my image column eachtime the grid is binded as the value in 'Notes' column can change.
Thanks once again ..
Regards
Shweta
0
Hello Shweta,
Thank you for your response.
The DataBindingComplete event is fired every time when the binding operation is finished. Of course, you should hook this event before setting the DataSource property. The following code demonstrates this behavior:
You could speed up the scrolling by turning on the fast scrolling feature. This can be done by setting the EnableFastScrolling property to true.
If you continue to experience problems with the scrolling, please open a support ticket and send us your application. We will be glad to find the best solution for your case.
Kind regards,
Jack
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Thank you for your response.
The DataBindingComplete event is fired every time when the binding operation is finished. Of course, you should hook this event before setting the DataSource property. The following code demonstrates this behavior:
private void Form2_Load(object sender, EventArgs e) |
{ |
Random r = new Random(); |
table.Columns.Add("ID", typeof(int)); |
table.Columns.Add("Name", typeof(string)); |
table.Columns.Add("Value", typeof(double)); |
table.Columns.Add("Image", typeof(Image)); |
table.Columns.Add("Check", typeof(bool)); |
for (int i = 0; i < 10000; i++) |
{ |
table.Rows.Add(i, "Row " + i, r.Next(20), null, r.Next(10) > 5 ? true : false); |
} |
this.radGridView1.DataBindingComplete += new GridViewBindingCompleteEventHandler(radGridView1_DataBindingComplete); |
this.radGridView1.DataSource = table; |
this.radGridView1.Columns["Check"].IsVisible = false; |
} |
void radGridView1_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e) |
{ |
Image bmp = Resources.red; |
for (int i = 0; i < this.radGridView1.Rows.Count; i++) |
{ |
if ((bool)this.radGridView1.Rows[i].Cells["Check"].Value) |
{ |
this.radGridView1.Rows[i].Cells["Image"].Value = bmp; |
} |
} |
} |
You could speed up the scrolling by turning on the fast scrolling feature. This can be done by setting the EnableFastScrolling property to true.
If you continue to experience problems with the scrolling, please open a support ticket and send us your application. We will be glad to find the best solution for your case.
Kind regards,
Jack
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.