我正在尝试将ImageComboBoxEdit控件添加到WinForms应用程序中的UserControl上。
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);
}
加载控件时:
我无法直接通过代码或在UI中更改当前。
functionKeyImageComboBoxEdit.SelectedIndex = 0;
我已尝试将事件附加到functionKeyImageComboBoxEdit,但这些似乎都没有被触发/捕获;
functionKeyImageComboBoxEdit.SelectedIndexChanged += FunctionKeyImageComboBoxEditOnSelectedIndexChanged;
private void FunctionKeyImageComboBoxEditOnSelectedIndexChanged(object sender, EventArgs eventArgs)
{
//throw new NotImplementedException();
}
我的代码中缺少什么?我一直在看DevExpress ImageComboBoxEdit Documentation,但看不出任何问题。
答案 0 :(得分:2)
问题的原因是您没有为ImageComboBoxItems设置值。这样做:
ImageComboBoxItem ctrlItem = new ImageComboBoxItem
{
Description = "Ctrl",
ImageIndex = 0,
Value = "Ctrl"
};
ImageComboBoxItem altItem = new ImageComboBoxItem
{
Description = "Alt",
ImageIndex = 1,
Value = "Alt"
};