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
close icon

Left align combobox display member in GridGroupingControl

I found the following code to left align the display member of a data bound combobox on the GridGroupingControl.
this.grid.TableDescriptor.Appearance.AnyRecordFieldCell. HorizontalAlignment = GridHorizontalAlignment.Left;

However this aligns any record to the left, and overwriting the alignment to right for a numeric data field has no effect on the amount grid column.
gcAmount.Appearance.AnyRecordFieldCell.Format = "#,###.##";
gcAmount.Appearance.AnyRecordFieldCell.TextAlign = GridTextAlign.Right;


The data bound GridGroupingControl contains a column PayeeId, this column is represented as a combobox bound to the Payee dataset using DisplayMember and ValueMember.
The alignment is correct on the dropdown list of the combobox.

What is the proper way of aligning the display member in combobox on the GridGroupingControl on the left and the amount column to the right?


5 Replies

NK Neelakandan Kannan Syncfusion Team December 15, 2016 01:01 PM UTC

Hi Patrick , 
Thanks for using Syncfusion products. 

Query: 
What is the proper way of aligning the display member in combobox on the GridGroupingControl on the left and the amount column to the right? 
 
 
Solution 1: 
We do not have the direct support to right align the drop down list of the combox. But you can achieve your scenario by using the TableModel. EnableGridListControlInComboBox, TableModel.EnableLegacyStyle property and handling the QueryCellInfo event for GridListControl. Please refer the below code snippet and refer the attached sample, 
 
Code snippet: 
this.gridGroupingControl1.TableModel.EnableGridListControlInComboBox = true; 
this.gridGroupingControl1.TableModel.EnableLegacyStyle = false; 
 
GridDropDownGridListControlCellRenderer ren= (this.gridGroupingControl1.TableControl.CellRenderers["ComboBox"] as GridDropDownGridListControlCellRenderer) ; 
control = (ren.ListControlPart as GridListControl); 
control.Grid.QueryCellInfo += Grid_QueryCellInfo; 
void Grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) 
{ 
    e.Style.HorizontalAlignment = GridHorizontalAlignment.Right; 
    e.Style.Format = "#,###.##";     
} 
 
 
Solution 2: 
You can achieve your scenario by using the GridListControl instead of ComboBox CellType. Please refer the below code snippet, 
 
Code snippet: 
this.gridGroupingControl1.TableDescriptor.Columns[3].Appearance.AnyRecordFieldCell.CellType = GridCellTypeName.GridListControl; 
GridDropDownGridListControlCellRenderer ren= (this.gridGroupingControl1.TableControl.CellRenderers["GridListControl"] as GridDropDownGridListControlCellRenderer) ; 
control = (ren.ListControlPart as GridListControl); 
control.Grid.QueryCellInfo += Grid_QueryCellInfo; 
 

Sample link: GridGroupingControl 

Reagards, 
Mohanraj G 



PL Patrick Luijpers December 15, 2016 03:14 PM UTC

Thank you Mohanraj for the example.

It is not working for me. I am trying to left align the text in the combobox (Payee) and right align invoice amount (see attached image).
Unable to successfully adapt your solutions to override the Payee combobox and align left.

Thanks,
Patrick

Attachment: Sample_Grid_Layout_17119381.zip


MG Mohanraj Gunasekaran Syncfusion Team December 16, 2016 11:06 AM UTC

Hi Patrick, 
 
Sorry for the inconvenience caused, 
 
By default, numeric column HorizontalAlignment is right and other column HorizontalAlignment is left. If you set the HorizontalAlignment as left using TableDescriptor.Appearance .AnyRecordFieldCell property. You should set the Right alignment for numeric column(Amount) using HorizontalAlignment property. Also, use the TextAlign property to align the RecordFieldCells. Please refer the below code snippet and refer the attached sample, 
 
Code snippet: 
this.gridGroupingControl1.TableDescriptor.Appearance.AnyRecordFieldCell.HorizontalAlignment = GridHorizontalAlignment.Left; 
this.gridGroupingControl1.TableDescriptor.Columns["Amount"].Appearance.AnyRecordFieldCell.HorizontalAlignment = GridHorizontalAlignment.Right; 
 
(or) 
 
this.gridGroupingControl1.TableDescriptor.Appearance.AnyRecordFieldCell.TextAlign =  GridTextAlign.Left; 
this.gridGroupingControl1.TableDescriptor.Columns["Amount"].Appearance.AnyRecordFieldCell.TextAlign = GridTextAlign.Right; 
 
 
 
 
Sample link:  GridGroupingcontrol 
 
Regards, 
Mohanraj G 
 



GM Gangabharathy Murugasen Syncfusion Team December 19, 2016 05:25 AM UTC

From: Patrick Luijpers [mailto:patrick@luijpers.com]
Sent: Friday, December 16, 2016 9:10 AM
To: Syncfusion Support <support@syncfusion.com>
Subject: Re: Syncfusion support community forum 127873, Left align combobox display member in GridGroupingControl, has been updated.
 

Thank you for this solution, simple and effective. 
 
  



MG Mohanraj Gunasekaran Syncfusion Team December 20, 2016 04:34 AM UTC

Hi Patrick,  
 
Thanks for your update. 
 
We are glad to know that your reported problem has resolved. Please Let us know if you need any further assistance.  
 
Regards, 
Mohanraj G. 


Loader.
Live Chat Icon For mobile
Up arrow icon