Back to Devexpress

RepositoryItemImageComboBox Class

windowsforms-devexpress-dot-xtraeditors-dot-repository-c2e09849.md

latest10.7 KB
Original Source

RepositoryItemImageComboBox Class

Represents a repository item which holds settings specific to ImageComboBoxEdit controls.

Namespace : DevExpress.XtraEditors.Repository

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXLicenseWinFormsEditors]
public class RepositoryItemImageComboBox :
    RepositoryItemImageComboBoxCore
vb
<DXLicenseWinFormsEditors>
Public Class RepositoryItemImageComboBox
    Inherits RepositoryItemImageComboBoxCore

The following members return RepositoryItemImageComboBox objects:

Remarks

The RepositoryItemImageComboBox class provides properties and events specific to ImageComboBoxEdit controls. You can access these settings via the editor’s ImageComboBoxEdit.Properties property.

The class inherits various properties and events controlling the editor’s appearance, popup window related settings, etc. The introduced properties specific to image combo boxes include:

You have to create standalone repository items only to specify inplace editors for container controls.

Examples

The code below shows how to create a RepositoryItemImageComboBox object in code, add it to a GridControl object’s repository, and assign it to a GridColumn object.

csharp
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Columns;

private RepositoryItemImageComboBox repositoryItemImageComboBox;

repositoryItemImageComboBox = new RepositoryItemImageComboBox();
// It is assumed that the GridControl object is created in the designer.
gridControl1.RepositoryItems.Add(repositoryItemImageComboBox);
repositoryItemImageComboBox.Items.AddRange(new DevExpress.XtraEditors.Controls.ImageComboBoxItem[] {
    new DevExpress.XtraEditors.Controls.ImageComboBoxItem("New", "New", 0),
    new DevExpress.XtraEditors.Controls.ImageComboBoxItem("Postponed", "Postponed", 1),
    new DevExpress.XtraEditors.Controls.ImageComboBoxItem("Fixed", "Fixed", 2),
    new DevExpress.XtraEditors.Controls.ImageComboBoxItem("Rejected", "Rejected", 3)
});
// It is assumed that the SvgImageCollection object is created in the designer.
repositoryItemImageComboBox.SmallImages = svgImageCollection1;
colStatus.ColumnEdit = repositoryItemImageComboBox;
vb
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraGrid.Columns

Private repositoryItemImageComboBox As RepositoryItemImageComboBox
repositoryItemImageComboBox = New DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox()
' It is assumed that the GridControl object is created in the designer.
gridControl1.RepositoryItems.Add(repositoryItemImageComboBox)
repositoryItemImageComboBox.Items.AddRange(New DevExpress.XtraEditors.Controls.ImageComboBoxItem() {
    New DevExpress.XtraEditors.Controls.ImageComboBoxItem("New", "New", 0),
    New DevExpress.XtraEditors.Controls.ImageComboBoxItem("Postponed", "Postponed", 1),
    New DevExpress.XtraEditors.Controls.ImageComboBoxItem("Fixed", "Fixed", 2),
    New DevExpress.XtraEditors.Controls.ImageComboBoxItem("Rejected", "Rejected", 3)
})
' It is assumed that the SvgImageCollection object is created in the designer.
repositoryItemImageComboBox.SmallImages = svgImageCollection1
colStatus.ColumnEdit = repositoryItemImageComboBox

The following code shows how to create an ImageComboBoxEdit control at runtime. In the custom AddItems method, several items are added using the ImageComboBoxItemCollection.Add method. For each item, we specify the caption, value and image index. The ImageCollection that stores images for items is created and populated at design time. It is assigned to the RepositoryItemImageComboBox.SmallImages property, providing images for items.

The ComboBoxEdit.SelectedIndexChanged event is used to display information on the selected item. The event handler displays the caption, value and index of the selected item in the form’s title.

The following image shows the form when the last item is selected.

csharp
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;

//ImageCollection storing images for items
private DevExpress.Utils.ImageCollection imageCollection1;

//image combo box editor created at runtime
DevExpress.XtraEditors.ImageComboBoxEdit rtImageComboBox;

private void Form1_Load(object sender, EventArgs e) {
    rtImageComboBox = CreateImageComboBoxEdit(new Rectangle(220, 10, 120, 20), this);
    AddItems(rtImageComboBox, imageCollection1);
    //select the last item
    rtImageComboBox.SelectedIndex = rtImageComboBox.Properties.Items.Count - 1;
}

//create the editor
private ImageComboBoxEdit CreateImageComboBoxEdit(Rectangle bounds, Control container) {
    ImageComboBoxEdit editor = new ImageComboBoxEdit();
    editor.Bounds = bounds;
    container.Controls.Add(editor);
    editor.SelectedIndexChanged += new EventHandler(imageComboBoxEdit_SelectedIndexChanged);
    return editor;
}

//add items
private void AddItems(ImageComboBoxEdit editor, ImageCollection imgList) {
    for (int i = 0; i < 7; i++)
        editor.Properties.Items.Add(new ImageComboBoxItem("Item " + (i + 1).ToString(), i, i));
    editor.Properties.SmallImages = imgList;
}

//display information on the selected item
void imageComboBoxEdit_SelectedIndexChanged(object sender, EventArgs e) {
    ImageComboBoxEdit editor = sender as ImageComboBoxEdit;
    this.Text = "SelectedIndexChanged: index " + editor.SelectedIndex.ToString() +
        " / value " + editor.EditValue.ToString() + " / display text " + editor.Text;
}
vb
Imports DevExpress.Utils
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls

'image combo box editor created at runtime
Private rtImageComboBox As DevExpress.XtraEditors.ImageComboBoxEdit

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
  Handles MyBase.Load
    rtImageComboBox = CreateImageComboBoxEdit(New Rectangle(220, 10, 120, 20), Me)
    AddItems(rtImageComboBox, imageList1)
    rtImageComboBox.SelectedIndex = rtImageComboBox.Properties.Items.Count - 1
End Sub

'create the editor
Private Function CreateImageComboBoxEdit(ByVal bounds As Rectangle, _
  ByVal container As Control) As ImageComboBoxEdit
    Dim editor As New ImageComboBoxEdit
    editor.Bounds = bounds
    container.Controls.Add(editor)
    AddHandler editor.SelectedIndexChanged, _
      New EventHandler(AddressOf imageComboBoxEdit_SelectedIndexChanged)
    Return editor
End Function

'add items
Private Sub AddItems(ByVal editor As DevExpress.XtraEditors.ImageComboBoxEdit, _
  ByVal imgList As ImageCollection)
    For i As Integer = 0 To 6
        editor.Properties.Items.Add(New ImageComboBoxItem("Item " & (i + 1).ToString(), i, i))
    Next
    editor.Properties.SmallImages = imgList
End Sub

'display information on a selected item
Sub imageComboBoxEdit_SelectedIndexChanged(ByVal sender As Object, _
  ByVal e As EventArgs)
    Dim editor As ImageComboBoxEdit = CType(sender, ImageComboBoxEdit)
    Me.Text = "SelectedIndexChanged: index " + editor.SelectedIndex.ToString() + _
     " / value " + editor.EditValue.ToString() + " / display text " + editor.Text
End Sub

Inheritance

Show 13 items

Object MarshalByRefObject Component DevExpress.XtraEditors.ComponentBase RepositoryItem RepositoryItemTextEdit RepositoryItemButtonEdit RepositoryItemPopupBase RepositoryItemPopupBaseAutoSearchEdit RepositoryItemComboBox DevExpress.XtraEditors.Repository.RepositoryItemImageComboBoxCore RepositoryItemImageComboBox RepositoryItemPickImage

See Also

RepositoryItemImageComboBox Members

ImageComboBoxEdit

Properties

DevExpress.XtraEditors.Repository Namespace