When we add items to a .net component, we usually need each item to be a (key-value) pair that matches an id-value in our business data model.
A .net ComboBox accepts adding an item as an “Object” and calling its toString() to place the item text and we can retrieve this object by the method SelectedItem.
I will create a class that represents a key-value pair, the objects created from this class will be added to the combobox:
EyComboBoxItem.cs
using System;
namespace EyReusableSystem
{
public class EyComboBoxItem
{
private string key;
public string Key
{
set
{
this.key = value;
}
get
{
return this.key;
}
}
private string val;
public string Val
{
set
{
this.val = value;
}
get
{
return this.val;
}
}
public EyComboBoxItem(string key, string val)
{
this.key = key;
this.val = val;
}
public override string ToString()
{
return this.val;
}
}
}
Read More…