This is a migrated thread and some comments may be shown as answers.

problem re populating/ resetting multiple comboboxes

1 Answer 52 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
newguy
Top achievements
Rank 1
newguy asked on 30 May 2013, 07:39 AM
Hi guys,

I have 5 Comboboxes, 1 main comboBox (Account) 3 additional ComboBoxes and 1 comboBox with a treeview that gets populated depending on the selected Value from the Main ComboBox. .

What is supposed to be happening is when i change select a new value from the Main comboBox all the other ones should be re populated with new data or cleared.

here is an example of how i am clearing the comboBoxes that depend on the Main one.

protected void cboAccount_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            RadComboBox cboSite = (RadComboBox)fvIncidentEdit.FindControl("cboSite");
            RadTreeView trvSite = ((RadTreeView)cboSite.Controls[2].FindControl("trvSite"));
            trvSite.DataSource = Models.Site.LoadActiveSites(Convert.ToInt32(e.Value));
            trvSite.DataBind();
            trvSite.UnselectAllNodes();
 
            cboSite.Text = string.Empty;
            cboSite.SelectedIndex = -1;
 
            PopulateSiteDependants();
        }
 
protected void PopulateSiteDependants()
        {
            RadTreeView trvSite = new RadTreeView();
            RadComboBox cboSite = (RadComboBox)fvIncidentEdit.FindControl("cboSite");
            if (cboSite.Controls[2].FindControl("trvSite") != null)
            {
                trvSite = ((RadTreeView)cboSite.Controls[2].FindControl("trvSite"));
             
                RadTreeView trvLocation = new RadTreeView();
                RadComboBox cboLocation = (RadComboBox)fvIncidentEdit.FindControl("cboLocation");
                if (cboLocation.Controls[2].FindControl("trvLocation") != null)
                {
                    if (trvSite.SelectedNode != null)
                    {
                        trvLocation = ((RadTreeView)cboLocation.Controls[2].FindControl("trvLocation"));
                        trvLocation.DataSource = Models.Location.LoadActiveLocations(Convert.ToInt32(trvSite.SelectedNode.Value));
                        trvLocation.DataBind();
                        trvLocation.UnselectAllNodes();
                    }
                    else
                    {
                        trvLocation.DataSource = null;
                    }
 
                    cboLocation.Text = string.Empty;
                    cboLocation.SelectedIndex = -1;
                }
 
                RadTreeView trvDepartment = new RadTreeView();
                RadComboBox cboDepartment = (RadComboBox)fvIncidentEdit.FindControl("cboDepartment");
                if (cboDepartment.Controls[2].FindControl("trvDepartment") != null)
                {
                    if (trvSite.SelectedNode != null)
                    {
                        trvDepartment = ((RadTreeView)cboDepartment.Controls[2].FindControl("trvDepartment"));
                        trvDepartment.DataSource = Models.Department.LoadActiveDepartments(Convert.ToInt32(trvSite.SelectedNode.Value));
                        trvDepartment.DataBind();
                        trvDepartment.UnselectAllNodes();
                    }
                    else
                    {
                        trvDepartment.DataSource = null;
                    }
 
                    cboDepartment.Text = string.Empty;
                    cboDepartment.SelectedIndex = -1;
                }
            }
            LoadCategories();
            
        }
 
        protected void LoadCategories()
        {
            RadTreeView trvDepartment = new RadTreeView();
            RadComboBox cboDepartment = (RadComboBox)fvIncidentEdit.FindControl("cboDepartment");
            if (cboDepartment.Controls[2].FindControl("trvDepartment") != null)
            {
                trvDepartment = ((RadTreeView)cboDepartment.Controls[2].FindControl("trvDepartment"));
 
                RadComboBox cboCategory = (RadComboBox)fvIncidentEdit.FindControl("cboCategory");
                RadTreeView trvCategory = (RadTreeView)cboCategory.Controls[2].FindControl("trvCategory");
                if (trvDepartment.SelectedNode != null)
                {
                    trvCategory.DataSource = Models.QuestionCategoryNode.LoadActiveQuestionCategoryNodes(Convert.ToInt32(trvDepartment.SelectedNode.Value));
                }
                else
                {
                    trvCategory.DataSource =Models.QuestionCategoryNode.LoadActiveQuestionCategoryNodes();
                }
                trvCategory.DataBind();
                trvCategory.UnselectAllNodes();
 
                cboCategory.Text = string.Empty;
                cboCategory.SelectedIndex = -1;
            }
        }


The only ComboBox that is giving me issues is the Category ComboBox, Please could someone explain the best way to clear / re populate a comboBox if the Main ComboBoxes value is changed.

Let me explain this properly.

The selection From ComboBox 1 Will populate comboBox 2.
When a selection from comboBox 2 is made, that will clear ComboBox 3 and 4 and will then populate ComboBox 3 and 4 with new data.
When a selection from comboBox 3 is made, that will clear ComboBox 5 and will then populate ComboBox 5 with new data.

The Above works but changing the Selected Value in the first comboBox  (account) will only Reset the 2nd ComboBox and not the rest.

So By selecting a new value From the 1st ComboBox that should reset comboBoxes 2-5 to an empty value.

1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 04 Jun 2013, 07:11 AM
Hello John,

I would suggest you to use the approach, demonstrated in this help article. If you still facing any issues, achieving the desired behavior, I would like to ask you to provide us with the configuration of the RadComboBoxes that you use at your side.

Regards,
Nencho
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ComboBox
Asked by
newguy
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or