Declined
Last Updated: 16 Feb 2024 20:24 by ADMIN
Ian
Created on: 07 Mar 2022 15:45
Category: UI for WinForms
Type: Feature Request
0
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 ?

2 comments
ADMIN
Dinko | Tech Support Engineer
Posted on: 16 Feb 2024 20:24

Hi Ian,

The feedback item status is changed to Declined due to inactivity in this thread.

Regards,
Dinko | Tech Support Engineer
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.

ADMIN
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;
            this.radGridView1.Columns.Add(decimalColumn);
            GridViewTextBoxColumn textColumn = new GridViewTextBoxColumn("Name");
            textColumn.TextAlignment = ContentAlignment.MiddleCenter;
            this.radGridView1.Columns.Add(textColumn);

            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?

Regards,
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.