8 Answers, 1 is accepted
0
Emanuel Varga
Top achievements
Rank 1
answered on 15 Nov 2012, 08:35 AM
Hello Larry,
Do you mean the Column Header?
Or what row header?
If you mean the column header you could just register for the DataBindingComplete event and then iterate trough the columns setting the column header you require.
The FieldName in this case is the property bounded to the column.
If you have any other questions, please let me know.
Best Regards,
Emanuel Varga
WinForms MVP
Do you mean the Column Header?
Or what row header?
If you mean the column header you could just register for the DataBindingComplete event and then iterate trough the columns setting the column header you require.
foreach
(var column
in
grid.Columns)
{
column.HeaderText =
"SomeHeader for field "
+ column.FieldName;
}
The FieldName in this case is the property bounded to the column.
If you have any other questions, please let me know.
Best Regards,
Emanuel Varga
WinForms MVP
0
Larry
Top achievements
Rank 1
answered on 15 Nov 2012, 09:22 AM
Hi,thanks for your response. i mean,row header not column header.
i want display row number in row header. now in datagrid the selected row
will display a icon that seem like a left arrow.
i want display row number in row header. now in datagrid the selected row
will display a icon that seem like a left arrow.
0
Emanuel Varga
Top achievements
Rank 1
answered on 15 Nov 2012, 09:37 AM
Hello,
Got it now, for this you should handle the ViewCellFormatting event and do something like this:
If you have any other questions, please let me know.
Best Regards,
Emanuel Varga
WinForms MVP
Got it now, for this you should handle the ViewCellFormatting event and do something like this:
void
grid_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(!(e.Row
is
GridViewDataRowInfo))
{
return
;
}
if
(e.CellElement
is
GridRowHeaderCellElement)
{
e.CellElement.Image =
null
;
e.CellElement.Text = (grid.CurrentView.ViewInfo.Rows.IndexOf(e.Row)+1).ToString();
}
}
If you have any other questions, please let me know.
Best Regards,
Emanuel Varga
WinForms MVP
0
Larry
Top achievements
Rank 1
answered on 16 Nov 2012, 02:12 AM
Hi,Thanks for your help. It is worked. But it can't auto change row header width, when content width is bigger than row header width, it is
display 1... How can i change row header width automaticly to display full row number.
display 1... How can i change row header width automaticly to display full row number.
0
Boo
Top achievements
Rank 2
answered on 16 Nov 2012, 05:50 AM
Hi Larry,
I used this
Boo.
I used this
_MyRadGrid.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
Boo.
0
Hi guys,
Thank you for writing.
@Boo - the AutoSizeColumnsMode property will fill the entire grid area with the columns, however, it will not change the width of the row header, as required.
Currently, it is not possible to dynamically set the width of the row header cell. However, there is a property, which allows you to set the width of all row headers cells in the control at once:
As already suggested, you should use the ViewCellFormatting event to achieve your scenario. More information about the formatting abilities of the control can be found in this documentation article: http://www.telerik.com/help/winforms/gridview-cells-formatting-cells.html.
Alternative way of accessing the RowIndex is to do it straight from the event arguments:
I hope that you find the provided information useful. Should you have any other questions, I will be glad to assist you.
Greetings,
Plamen
the Telerik team
Thank you for writing.
@Boo - the AutoSizeColumnsMode property will fill the entire grid area with the columns, however, it will not change the width of the row header, as required.
Currently, it is not possible to dynamically set the width of the row header cell. However, there is a property, which allows you to set the width of all row headers cells in the control at once:
radGridView1.TableElement.RowHeaderColumnWidth = 100;
As already suggested, you should use the ViewCellFormatting event to achieve your scenario. More information about the formatting abilities of the control can be found in this documentation article: http://www.telerik.com/help/winforms/gridview-cells-formatting-cells.html.
Alternative way of accessing the RowIndex is to do it straight from the event arguments:
void
radGridView1_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement
is
GridRowHeaderCellElement && e.Row
is
GridViewDataRowInfo)
{
e.CellElement.Image =
null
;
e.CellElement.Text = (e.RowIndex + 1).ToString();
}
}
I hope that you find the provided information useful. Should you have any other questions, I will be glad to assist you.
Greetings,
Plamen
the Telerik team
0
Larry
Top achievements
Rank 1
answered on 20 Nov 2012, 04:02 AM
Hi, that's a perfect answer. But i want to know how to calculate row header text width automaticly.For example, when row number is 12,the width is 20. when row number is 100 the width is 30. Could you tell me a way to calculate the text pixel width or point width ?
0
Hello guys,
@Larry - Currently, the width of the row header cell does not support auto-resize. As I already suggested, you could use an alternative way:
A way to calculate the width of the text is:
Another way to calculate the text width is to use the Graphics.MeasureString Method or the Windows Forms static TextRenderer.MeasureText Method.
Kind regards,
Plamen
the Telerik team
@Larry - Currently, the width of the row header cell does not support auto-resize. As I already suggested, you could use an alternative way:
radGridView1.TableElement.RowHeaderColumnWidth = 100;
A way to calculate the width of the text is:
e.CellElement.ColumnInfo.Width = Math.Max(e.CellElement.ColumnInfo.Width, newWidth);
Another way to calculate the text width is to use the Graphics.MeasureString Method or the Windows Forms static TextRenderer.MeasureText Method.
TextRenderer uses GDI to render the text, whereas Graphics uses GDI+. The two use a slightly different method for laying out text so the sizes are different.
Which one you should use depends on what will eventually be used to actually draw the text. If you are drawing it with GDI+ Graphics.DrawString, measure using Graphics.MeasureString. If you are drawing using GDI TextRenderer.DrawText, measure using TextRenderer.MeasureText.
Kind regards,
Plamen
the Telerik team