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

Related Dropdown(ComboBox) with GridGroupingcontrol

Thread ID:

Created:

Updated:

Platform:

Replies:

118153 Feb 5,2015 10:12 AM UTC Feb 8,2015 06:11 AM UTC Windows Forms 1
loading
Tags: GridDataBoundGrid(Classic)
Ramin Alirezaee
Asked On February 5, 2015 10:12 AM UTC

Hi.
I want change ComboBox items by some condition in each row.
I found a solution in Enum localizatin sample. But it doesn't work.

void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
        {
            var el = e.TableCellIdentity;
            var item = el.DisplayElement != null ? el.DisplayElement.GetData() : null;

            if (item is Employee &&
                el.Column != null &&
                el.Column.FieldDescriptor != null &&
                el.Column.FieldDescriptor.FieldPropertyType.IsEnum &&
                (el.DisplayElement.Kind == DisplayElementKind.Record
                 || el.DisplayElement.Kind == DisplayElementKind.AddNewRecord))
            {
                var context = new TypeDescriptorContext(item, e.Style.PropertyDescriptor);
                var converter = e.Style.PropertyDescriptor.Converter;
                if (converter != null)
                {
                    var contextualValues = converter.GetStandardValues(context).OfType<object>().ToArray();
                    e.Style.CellType = "ComboBox";
                    if (!checkBox1.Checked)
                        e.Style.DataSource = contextualValues;
                   
                }
            }

        }
//----------------------------------------------------
private System.Collections.ICollection GetContextualCollection(Context employeeContext)
        {
            switch (employeeContext)
            {
                case Context.Employed:
                    return new Collection<Status>{ Status.Married, Status.Single, Status.Widow };
                case Context.OnVacation:
                    return new Collection<Status>{ Status.Married };
                case Context.Retired:
                    return new Collection<Status>{ Status.Single, Status.Divorced };
                case Context.Sick:
                    return new Collection<Status>{ Status.Widow};
                default:
                    return new Collection<Status>{ Status.Married, Status.Single, Status.Widow, Status.Divorced };
           }
        }

Thanks.

Neelakandan Kannan [Syncfusion]
Replied On February 8, 2015 06:11 AM UTC

Hi Ramin,

 

Thank you for using Syncfusion products.

 

Here we have provided the sample as per your need. In the below sample if you change the datasource, the Combobox item will be changed dynamically as per Datasource. Please make use of below code,

 

Code Snippet:

void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)

        {

            if (e.TableCellIdentity.RowIndex > 2 && e.TableCellIdentity.Column!=null)

            {               

                if (defaultDatasource && e.TableCellIdentity.Column.Name=="Data1")

                {

                    e.Style.CellType = GridCellTypeName.ComboBox;

                    e.Style.ChoiceList = defaultDatasourcelist;

                }

                if(employeeDatasource && e.TableCellIdentity.Column.Name=="Data2")

                {

                    e.Style.CellType = GridCellTypeName.ComboBox;

                    e.Style.ChoiceList = employeeDatasourcelist;

                }

            }

 

 

Please let me know if you have any concerns.

 

Regards,

Neelakandan


Attachment: GridGroupingControl_Demo_4aaf7eab.zip

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

;