Need More Info
Last Updated: 10 Mar 2022 08:52 by ADMIN
Created on: 07 Mar 2022 15:45
Category: UI for WinForms
Type: Feature Request
GridView default text allignment

GridView has a default text alignment for new columns as 'MiddleCenter'.

Default alignment for new GridViewDataRowInfo is 'left'.

Please can these be the same ?

1 comment
Dess | Tech Support Engineer, Principal
Posted on: 10 Mar 2022 08:52
 Hello, Ian,

The default text alignment in RadGridView's columns is different for the different column types. For example, GridViewDecimalColumn has ContentAlignment.MiddleRight and GridViewTextBoxColumn is left aligned.

However, each column offers TextAlignment property allowing you to control how the text to be aligned: 

            GridViewDecimalColumn decimalColumn = new GridViewDecimalColumn("Id");
            decimalColumn.TextAlignment = ContentAlignment.MiddleCenter;
            GridViewTextBoxColumn textColumn = new GridViewTextBoxColumn("Name");
            textColumn.TextAlignment = ContentAlignment.MiddleCenter;

            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

            for (int i = 0; i < 10; i++)
                this.radGridView1.Rows.Add(i, "Row" + i);

For the new row, the column's TextAlignment is also considered:


As to the editor which is activated, indeed, it is always left aligned which is expected. If you need to manage the editor's text alignment, it is necessary to do it in the CellEditorInitialized event: 

        private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
            RadTextBoxEditor textEditor = e.ActiveEditor as RadTextBoxEditor;
            GridSpinEditor  spinEditor = e.ActiveEditor as GridSpinEditor;

            if (textEditor!=null)
                RadTextBoxEditorElement el = textEditor.EditorElement as RadTextBoxEditorElement;
                el.TextAlign = HorizontalAlignment.Center;
            else if (spinEditor!=null)
                RadSpinEditorElement el = spinEditor.EditorElement as RadSpinEditorElement;
                el.TextAlignment = HorizontalAlignment.Center;


Please give it a try and see how it works for your scenario.

I have updated this request's status to "Need More Info" as it is not quite clear to me what is the exact requirement that you are trying to acomplish. Could you please elaborate?

Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.