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

eccur an exeption after changing font

1 Answer 104 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Masoud
Top achievements
Rank 1
Masoud asked on 19 Jan 2011, 04:20 PM
Hi to all Telerik fans and its experts:
i try change column font with use "Element hierarchy editor".
it is done but just in Design mode and after Running project eccur an exeption in designer code.
Please notice following code block from my designer code:
// Error Line-->((Telerik.WinControls.UI.GridHeaderCellElement)(this.raGridView1.GetChildAt(0).GetChildAt(1).GetChildAt(0).GetChildAt(1))).IsCurrent = false;//<-- Error Line
((Telerik.WinControls.UI.GridHeaderCellElement)(this.radGridView1.GetChildAt(0).GetChildAt(1).GetChildAt(0).GetChildAt(1))).IsCurrentColumn = false;
((Telerik.WinControls.UI.GridHeaderCellElement)(this.radGridView1.GetChildAt(0).GetChildAt(1).GetChildAt(0).GetChildAt(1))).IsSorted = true;
((Telerik.WinControls.UI.GridHeaderCellElement)(this.radGridView1.GetChildAt(0).GetChildAt(1).GetChildAt(0).GetChildAt(1))).IsPinned = false;
((Telerik.WinControls.UI.GridHeaderCellElement)(this.radGridView1.GetChildAt(0).GetChildAt(1).GetChildAt(0).GetChildAt(1))).Image = null;
((Telerik.WinControls.UI.GridHeaderCellElement)(this.radGridView1.GetChildAt(0).GetChildAt(1).GetChildAt(0).GetChildAt(1))).Text = "??? ? ??? ????????";
((Telerik.WinControls.UI.GridHeaderCellElement)(this.radGridView1.GetChildAt(0).GetChildAt(1).GetChildAt(0).GetChildAt(1))).Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
((Telerik.WinControls.UI.GridHeaderCellElement)(this.radGridView1.GetChildAt(0).GetChildAt(1).GetChildAt(0).GetChildAt(1))).Padding = new System.Windows.Forms.Padding(0, 0, 16, 0);

Exception Message:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


i cut this code block  and past it in the Form Load Event and this problem was solved And this is not that interesting for me.

But why?
Whether the telerik GridView control has an Bug?

1 Answer, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 19 Jan 2011, 04:29 PM
Hello,

To change the font of cells you should use either the CellFormatting event or the ViewCellFormatting event depending on the cell you want to change. CellFormatting fires for data rows, whereas ViewCellFormatting also fires for system rows (such as the header)
Have a look at this documentation for more information.

If you have further questions please let me know
Richard
Tags
GridView
Asked by
Masoud
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Share this question
or