change text alignment in editing mode for gridview

2 posts, 0 answers
  1. shahrooz
    shahrooz avatar
    2 posts
    Member since:
    Dec 2014

    Posted 13 Mar 2015 Link to this post

    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 can change that to center to?
  2. Ralitsa
    Ralitsa avatar
    183 posts

    Posted 17 Mar 2015 Link to this post

    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.


    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.

Back to Top