We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Align CellButton's text to center

Hello,

I have a ButtonColumn with multiple buttons. I not find the proper CellButton property to align the text center (horizontal). 



I follow this example: https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataGrid.GridButtonColumn.html#%22%22

Can you help me please align the text center?

Thank you!

BR, SZL


3 Replies 1 reply marked as answer

SJ Sathiyathanam Jeyakumar Syncfusion Team January 12, 2023 04:26 PM UTC

Hi SZL,

To center the text in a button column, you can use the column cell style. You should set the HorizontalAlignment property to 'Center' and then bind this cell style to the button column. This will ensure that the text in the button is centered. Refer to the below code snippets to get more information.

List<CellButton> buttons = new List<CellButton>();

buttons.Add(new CellButton() { Text = "B", AutoSize = false});

buttons.Add(new CellButton() { Text = "M", AutoSize = false });

buttons.Add(new CellButton() { Text = "T", AutoSize = false });

buttons.Add(new CellButton() { Text = "C", AutoSize = false });

buttons.Add(new CellButton() { Text = "L", AutoSize = false });

 

CellStyleInfo cellStyleInfo = new CellStyleInfo();

cellStyleInfo.HorizontalAlignment = HorizontalAlignment.Center;

this.sfDataGrid1.Columns.Add(new GridButtonColumn()

{

    Buttons = buttons,

    CellStyle = cellStyleInfo

               

});




Regards,

Sathiyathanam


Attachment: SfDataGrid_GridButtonColumn_c253b8b0.zip

Marked as answer

SZ SZL replied to Sathiyathanam Jeyakumar January 21, 2023 07:29 PM UTC

Hi,


Thank you very much, its working well!


BR, SZL



SJ Sathiyathanam Jeyakumar Syncfusion Team January 23, 2023 09:04 AM UTC

SZL,

We are glad that the provided response meets your requirement. Please let us know if you need further assistance. As always, we are happy to help you out. 


Loader.
Live Chat Icon For mobile
Up arrow icon