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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Format DisplayMember in GGC and in ComboboxAdv

Thread ID:

Created:

Updated:

Platform:

Replies:

127180 Nov 1,2016 06:31 AM UTC Nov 4,2016 04:41 AM UTC Windows Forms 3
loading
Tags: GridGroupingControl
Nicolas
Asked On November 1, 2016 06:31 AM UTC

Hi, I have a combo in both GGC and cboAdv where I have to format a date, for say "dd/MM/yy" in the DisplayMember. The ValueMember is an integer, how can I format the DisplayMember? Thanks in advance! - Nicolas

Piruthiviraj Malaimelraj [Syncfusion]
Replied On November 2, 2016 01:26 PM UTC

Hi Nicolas, 
 
Thanks for your interest in Syncfusion products. 
 
In order to apply the format for display member of the ComboBox , you need to customize the GridComboBoxCellModel and GidComboBoxCellRenderer. Please make use of the below code, 
 
Code example 
 
this.gridGroupingControl1.TableModel.CellModels.Add("CustomComboBox", new GridComboBoxCellModelAdv(this.gridGroupingControl1.TableModel)); 
 
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.CellType = "CustomComboBox"; 
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.DataSource = GetTable(); 
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.DisplayMember = "Value"; 
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.ValueMember = "ID"; 
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.Format = "dd/MM/yy"; 
 
//Custom_ComboBoxCellModel: 
public class GridComboBoxCellModelAdv : GridComboBoxCellModel 
{ 
    public GridComboBoxCellModelAdv(GridModel grid) 
        : base(grid) 
    { 
        AllowFloating = false; 
        ButtonBarSize = new Size(SystemInformation.VerticalScrollBarWidth, 0); 
        SupportsChoiceList = true; 
    } 
 
    public override GridCellRendererBase CreateRenderer(GridControlBase control) 
    { 
        return new GridComboBoxCellRendererAdv(control, this); 
    } 
 
    public override string GetFormattedText(GridStyleInfo style, object value, int textInfo) 
    { 
        if (style.Format != string.Empty) 
        { 
            DateTime date = new DateTime(); 
            if (DateTime.TryParse(base.GetFormattedText(style, value, textInfo), out date)) 
            { 
                value = date.ToString(style.Format); 
            } 
            else if (style.CellValueType == typeof(string)) 
            { 
                value = string.Format("{0:" + style.Format + "}", base.GetFormattedText(style, value, textInfo)); 
            } 
        } 
 
        return base.GetFormattedText(style, value, textInfo); 
    } 
} 
//Custom_ComboBoxCellRenderer: 
public class GridComboBoxCellRendererAdv : GridComboBoxCellRenderer 
{ 
    public GridComboBoxCellRendererAdv(GridControlBase grid, GridCellModelBase cellModel) 
        : base(grid, cellModel) 
    { 
        DropDownImp.InitFocusEditPart = true; 
        DropDownButton = new GridCellComboBoxButton(this); 
    } 
 
    protected override void OnSetControlText(string text) 
    { 
        if (StyleInfo.Format != string.Empty) 
        { 
            DateTime date = new DateTime(); 
            if (DateTime.TryParse(text, out date)) 
            { 
                text = date.ToString(StyleInfo.Format); 
            } 
            else if (StyleInfo.CellValueType == typeof(string)) 
            { 
                text = string.Format("{0:" + StyleInfo.Format + "}", text); 
            } 
        } 
        base.OnSetControlText(text); 
    } 
} 
 
Sample link 

Regards, 
Piruthiviraj 


Nicolas
Replied On November 3, 2016 04:20 PM UTC

Works great! Thank you! - Nicolas

Piruthiviraj Malaimelraj [Syncfusion]
Replied On November 4, 2016 04:41 AM UTC

Hi Nicolas, 

Thanks for the update. 

We are glad to know that the given solution is resolved your scenario. Please let us know if you have any other queries. 

Regards, 
Piruthiviraj 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;