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

How to set CommandColumn style?

3 Answers 163 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Stanley
Top achievements
Rank 1
Stanley asked on 18 May 2012, 11:04 AM
1. TextAlignment = ContentAlignment.MiddleCenter;
2. Bold = true;


        private void gv_CellFormatting(object sender, CellFormattingEventArgs e)
        {
            if (e.CellElement.ColumnInfo is GridViewCommandColumn)
            {
                int index = (int)e.CellElement.RowInfo.Cells[0].Value - 1;
                ((RadButtonElement)e.CellElement.Children[0]).TextAlignment = ContentAlignment.MiddleCenter;
                ((RadButtonElement)e.CellElement.Children[0]).Font.Bold = True;
            }  
        }

Please refer picture from attachment.
Who can help me? :)
Thank You.

3 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 23 May 2012, 06:28 AM
Hello Stanley,

Thank you for your question.

Here is how you can do that:
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.ColumnInfo is GridViewCommandColumn)
    {
        ((GridCommandCellElement)e.CellElement).CommandButton.TextElement.StretchHorizontally = true;
        ((GridCommandCellElement)e.CellElement).CommandButton.TextElement.TextAlignment = ContentAlignment.MiddleCenter;
    }
}

I hope this helps. Let us know if you have any other questions.
 
Kind regards,
Stefan
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Stanley
Top achievements
Rank 1
answered on 23 May 2012, 07:06 AM
Hi Telerik,

Is able to set Font Bold = true?
The below property is get value only but cannot set it.
((GridCommandCellElement)e.CellElement).CommandButton.TextElement.Font.Bold = true;

Thank You.
0
Accepted
Ivan Petrov
Telerik team
answered on 25 May 2012, 01:24 PM
Hi Stanley,

All style properties of the Font class are read-only. To change the style of a font you have to create a new font instance. Here is a sample snippet:
TextPrimitive text =((GridCommandCellElement)e.CellElement).CommandButton.TextElement;
text.Font = new Font(text.Font, FontStyle.Bold);

I hope this will be useful. If you have further questions, I would be glad to help.

Regards,
Ivan Petrov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Stanley
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Stanley
Top achievements
Rank 1
Ivan Petrov
Telerik team
Share this question
or