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

change text alignment in editing mode for gridview

1 Answer 240 Views
GridView
This is a migrated thread and some comments may be shown as answers.
shahrooz
Top achievements
Rank 1
shahrooz asked on 13 Mar 2015, 07:34 AM
i used a rad grid view in win form app.i changed text alignment to center in normal mode with cell formatting.but when i clicked on cell to edit that ,alignment is left.how can change that to center to?

1 Answer, 1 is accepted

Sort by
0
Ralitsa
Telerik team
answered on 17 Mar 2015, 12:05 PM
Hello Shahrooz,

Thank you for contacting us. 

You can access the editors in the CellEditorInitialized event and change the TextAlignment property to HorizontalAlignment.Center. In order to achieve your goal, please have a look at the following code snippet:
void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
    RadTextBoxEditor textEditor = e.ActiveEditor as RadTextBoxEditor;
    GridSpinEditor spinEditor = e.ActiveEditor as GridSpinEditor;
 
    if (spinEditor != null)
    {
        GridSpinEditorElement el = spinEditor.EditorElement as GridSpinEditorElement;
        el.TextAlignment = HorizontalAlignment.Center;
    }
 
    if (textEditor != null)
    {
        RadTextBoxEditorElement el = textEditor.EditorElement as RadTextBoxEditorElement;
        el.TextAlign = HorizontalAlignment.Center;
    }
}

The example demonstrates how to set the alignment of two editors (textbox editor and spin editor). If you use another editor in you application, you need to set their alignment too. 

I also attached a sample demo. 

Should you have further questions, I would be glad to help.

Regards,
Ralitsa
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
shahrooz
Top achievements
Rank 1
Answers by
Ralitsa
Telerik team
Share this question
or