2015-10-14 15 views
0

我想添加一个ImageComboBoxEdit控件到我的WinForms应用程序中的UserControl上。ImageComboBoxEdit选择的值不可设置

public ShortCutUserControl() 
{ 
    var imageCollection = new ImageCollection { ImageSize = new Size(48, 48) }; 
    imageCollection.Images.Add(Image.FromFile(@"Keyboard\ctrl.ico")); 
    imageCollection.Images.Add(Image.FromFile(@"Keyboard\alt.ico")); 
    functionKeyImageComboBoxEdit.Properties.LargeImages = imageCollection; 

    ImageComboBoxItem ctrlItem = new ImageComboBoxItem 
    { 
     Description = "Ctrl", 
     ImageIndex = 0 
    }; 
    ImageComboBoxItem altItem = new ImageComboBoxItem 
    { 
     Description = "Alt", 
     ImageIndex = 1 
    }; 
    functionKeyImageComboBoxEdit.Properties.Items.Add(altItem); 
    functionKeyImageComboBoxEdit.Properties.Items.Add(ctrlItem); 
} 

当控制被加载:

User Control

我不能直接通过代码或在UI或者更改当前。

functionKeyImageComboBoxEdit.SelectedIndex = 0; 

我试着将事件附加到functionKeyImageComboBoxEdit,但没有一个似乎被解雇/捕获;

functionKeyImageComboBoxEdit.SelectedIndexChanged += FunctionKeyImageComboBoxEditOnSelectedIndexChanged; 

private void FunctionKeyImageComboBoxEditOnSelectedIndexChanged(object sender, EventArgs eventArgs) 
{ 
    //throw new NotImplementedException(); 
} 

我从代码中遗漏了什么?我一直在寻找DevExpress ImageComboBoxEdit Documentation,但看不到任何问题。

回答

2

问题的原因是您没有为ImageComboBoxItems设置值。这样做:

ImageComboBoxItem ctrlItem = new ImageComboBoxItem 
{ 
    Description = "Ctrl", 
    ImageIndex = 0, 
    Value = "Ctrl" 
}; 
ImageComboBoxItem altItem = new ImageComboBoxItem 
{ 
    Description = "Alt", 
    ImageIndex = 1, 
    Value = "Alt" 
};