Home Forums WinForms controls Xceed Grid for WinForms Dynamically populated ComboBox

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #15745 |

    Hi there

    I have an unbound grid that have two columns with ComboBoxes.
    The first ComboBox contains items from a table. What i need to do is to load a different set of items in the second ComboBox depending on what is selected in the first ComboBox.

    Does anyone know how to do that?

    And a second question.
    Is it possible to combine bound and unbound items in a ComboBox? The idea that i have is to load some items in to the ComboBox from a table but allow user to open a search dialog when the unbound item is selected. For example if the list is large, it would be good to have one item (probably first one) which can be used to open a more comprehensive search dialog to make it easier for users to find the item they want to select.


    Imported from legacy forums. Posted by Alexander (had 3038 views)

    User (Old forums)
    Post count: 23064

    there are many ways to do this.
    I have found that the simplest way is to populate the items in the combo box when the combo box has focus;
    xaml example:
    <xcdg:CellEditor x:Key=”GradeCellEditor”>
    <ComboBox BorderThickness=”0″
    Text=”{Binding RelativeSource={RelativeSource FindAncestor,
    Tag=”{Binding RelativeSource={RelativeSource FindAncestor,

    //…Code behind;
    private void GradeComboBox_GotFocus(object sender, RoutedEventArgs e)
    ComboBox cb = sender as ComboBox;
    if (cb != null)
    if (cb.ItemsSource == null)
    DataCell ms = cb.Tag as DataCell;
    if (ms != null)
    ISize g = ms.DataContext as ISize;
    if (g != null)
    if (g.size.HasValue() && g.type.HasValue())
    cb.ItemsSource = InitGrades(g.type, g.size);
    else if (g.type.HasValue())
    cb.ItemsSource = InitGrades(g.type);
    IMType ty = ms.DataContext as IMType;
    if (ty != null)
    cb.ItemsSource = InitGrades(ty.type);

    Hope you find this example OK
    I just copied and pasted my code so dont worry about the objects you dont know about.
    the Tag filed is bound to the cell and the cell.datacontext is the rows datasource(your object)

    I havenet seem much loss in speed vs. having the itemssource set in Xaml.
    I have put the if(combobox.itemssource == null) in for speed reasons in not reloading the data
    but every time a cell is edited the itemssource on the combobox is always null. To me this means the combobox is created each time you enter edit mode on that cell.

    As for unbound items in a combobox I have some tricks for that.
    It has to do with the collection bound to the items source. not the combobox iteself.
    look at this article I found to get more ideas

    Imported from legacy forums. Posted by MiddleTommy (had 520 views)

    User (Old forums)
    Post count: 23064

    Sorry wrong forum
    this is for the WPF grid
    but the same priciples apply just not all the code.

    Imported from legacy forums. Posted by MiddleTommy (had 250 views)

    User (Old forums)
    Post count: 23064

    Thanks MiddleTommy

    Your code doesn’t make sense to me but your tip was good.
    I’m trying to implement what i need by populating the ComboBox when the control is activated.

    Again, thanks for the tip.


    Imported from legacy forums. Posted by Alexander (had 3875 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.