Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
250
Can't set default value in UltraComboEditor containing list of objects
posted

I'm having a problem selecting a default value in a  UltraComboEditor that contains a List of custom objects.

Things that are special about this is that I'm creating the combo boxes on the fly and adding them to a tablelayout panel. Othwerwise, this should be a very simple thing:

Here's the code:

                UltraComboEditor questionChoices = new UltraComboEditor();
                questionChoices.DropDownStyle = Infragistics.Win.DropDownStyle.DropDownList;
                questionChoices.DisplayMember = "Name";
                questionChoices.ValueMember = "ScoringGuideId";
                questionChoices.DataSource = m_InputData.Questions[i].Choices;
                for (int choiceIndex = 0; choiceIndex < m_InputData.Questions[i].Choices.Count; choiceIndex++)
                {
                    if (m_InputData.Questions[i].Choices[choiceIndex].IsSelected == 1)
                        questionChoices.Value = m_InputData.Questions[i].Choices[choiceIndex];
                }

                questionChoices.SelectionChanged += QuestionComboBox__SelectionChanged;
                m_questionTable.Controls.Add(questionChoices, 1, i);

 

I can't do anything with the combo box, every time i set the value or the selected index, the value is always null and the selected index is -1.  However, when the form renders, the items are in the list..just nothing is selected.

Interestingly, debugging through the code, after I set the datasource, the combobox says it has 0 items in it (a clue as to what is wrong here).  I tried to call databind() after setting the datasource, but it said that there is no binding context (I've not had to use binding context for other controls before where I assigned a datasource and called databind).

 

Any help?

 

 

 

  • 250
    Suggested Answer
    posted

    Hi I figured it out, it was 2 things.

    First, need to add the control to the container before setting the datasource.  I learned of this in another post on the site about the same sort of problem.

    Second, I don't use the .Value property to set the selected item, instead I set the SelectedIndex to the index of the item I want to select. The .Value property didn't work for some reason, but I'm happy to use the selected index option.