Back to Devexpress

ComboBoxItem.Value Property

windowsforms-devexpress-dot-xtraeditors-dot-controls-dot-comboboxitem.md

latest4.5 KB
Original Source

ComboBoxItem.Value Property

Gets or sets the item value. This value is assigned to the editor’s edit value when users select the item.

Namespace : DevExpress.XtraEditors.Controls

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue(null)]
[DXCategory("Data")]
public virtual object Value { get; set; }
vb
<DefaultValue(Nothing)>
<DXCategory("Data")>
Public Overridable Property Value As Object

Property Value

TypeDefaultDescription
Objectnull

The item value.

|

Remarks

When you create items for an ImageComboBoxEdit editor, assign a unique value to each item through its Value property. For a ComboBoxEdit editor, there is no need to create ComboBoxItem object instances, as you may assign values directly to an editor:

csharp
CheckedComboBoxEdit comboBox = new CheckedComboBoxEdit();
comboBox.Properties.Items.Add("Value 1");
comboBox.Properties.Items.AddRange(new object[] {"Value 2","Value 3" });
vb
Dim comboBox As New CheckedComboBoxEdit()
comboBox.Properties.Items.Add("Value 1")
comboBox.Properties.Items.AddRange(New Object() {"Value 2","Value 3" })

The code sample below illustrates how to create an Image Combo Box with 3 values.

csharp
ImageComboBoxEdit imageComboBox = new ImageComboBoxEdit();
imageComboBox.Bounds = new Rectangle(220, 10, 120, 20);
ImageCollection comboBoxImages = new ImageCollection();
comboBoxImages.AddImage(Image.FromFile(".\\photo1.png"));
comboBoxImages.AddImage(Image.FromFile(".\\photo2.png"));
comboBoxImages.AddImage(Image.FromFile(".\\photo3.png"));
imageComboBox.Properties.LargeImages = comboBoxImages;
for (int i = 0; i < comboBoxImages.Images.Count; i++)
    imageComboBox.Properties.Items.Add(new ImageComboBoxItem { Value = i+1, ImageIndex = i, Description = string.Format("Photo {0}",(i+1).ToString()) });
imageComboBox.SelectedIndexChanged += (o, e) =>
{
    ImageComboBoxEdit edit = o as ImageComboBoxEdit;
    XtraMessageBox.Show(string.Format("You have selected photo {0}",edit.EditValue.ToString()));
};
this.Controls.Add(imageComboBox);
vb
Dim imageComboBox As New ImageComboBoxEdit()
imageComboBox.Bounds = New Rectangle(220, 10, 120, 20)
Dim comboBoxImages As New ImageCollection()
comboBoxImages.AddImage(Image.FromFile(".\photo1.png"))
comboBoxImages.AddImage(Image.FromFile(".\photo2.png"))
comboBoxImages.AddImage(Image.FromFile(".\photo3.png"))
imageComboBox.Properties.LargeImages = comboBoxImages
For i As Integer = 0 To comboBoxImages.Images.Count - 1
    imageComboBox.Properties.Items.Add(New ImageComboBoxItem With {.Value = i+1, .ImageIndex = i, .Description = String.Format("Photo {0}",(i+1).ToString())})
Next i
AddHandler imageComboBox.SelectedIndexChanged, Sub(o, e)
    Dim edit As ImageComboBoxEdit = TryCast(o, ImageComboBoxEdit)
    XtraMessageBox.Show(String.Format("You have selected photo {0}",edit.EditValue.ToString()))
End Sub
Me.Controls.Add(imageComboBox)

See Also

ImageComboBoxItem

SelectedIndex

ComboBoxEdit.SelectedItem

ImageComboBoxEdit.SelectedItem

SelectedValueChanged

Description

ImageIndex

ComboBoxItem Class

ComboBoxItem Members

DevExpress.XtraEditors.Controls Namespace