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
1160
How do I populate a ComboEditorTool combobox programmatically?
posted

I tried the following and get "Object reference not set to an instance of an object." when I try to add the first item (a string) to the combobox (there is a value in s at the time).  What's the correct way to do this:

XAML snippet:

 <igRibbon:RibbonTabItem Header="Skins">

<igRibbon:RibbonGroup Id="skins" Caption="Skins" >

<igRibbon:ComboEditorTool

Id="cetSkins"

x:Name="cetSkins"

DropDownResizeMode="VerticalOnly"

IsEditable="False"

SelectedItemChanged="cetSkins_SelectedItemChanged"/>

</igRibbon:RibbonGroup>

 Code:

 public Window1()

{

InitializeComponent();

string[ f = Directory.GetFiles("skins", "skin*.xaml");

foreach (string s in f)

this.cetSkins.ComboBox.Items.Add(s);

I've also tried putting my code in as separate Window_Loaded event but that fails the same way.

 

Thanks!

 Glenn L

Parents
  • 8576
    Offline posted

    Hi Glenn -

    The ComboEditorTool (as well as the XamComboEditor control from which it is derived) get their data from a special object called ComboBoxItemsProvider.  The ComboBoxItemsProvider (which exposes an Items property as well as an ItemsSource property) is hooked up to the ComboEditorTool by assigning an instance of it to the ItemsProvider property of the ComboEditorTool.  

    WIth this in mind you would modify your code to create a ComboBoxItemsProvider, add the strings to the Items proeprty of the ComboBoxItemsProvider and then set the ItemsProvider property of the ComboEditorTool to the ComboBoxItemsProvider instance.

    Note: A ComboBoxItemsProvider instance can be assigned to multiple ComboEditorTool instances for efficiency purposes if the drop down items are the same across those ComboEditorTools. The ComboBoxItemsProvider object is the one that manages the items and binding to the items source.

    Joe Modica

Reply Children
No Data