You could also use a NameObjectCollectionBase to hold the values, or a one-dimensional array of a custom objects to hold the display and value data:
Public Class myPair
Public Display as String
Public Value as Integer
End Class
Dim mySource(10) as myPair
' oops, forgot to instance the class
mySource(0) = New myPair
mySource(0).Display = 'One'
mySource(0).Value = 1
. . . . . .
cboMyBox.DataSource = mySource
cboMyBox.DisplayMember = "Display"
cboMyBox.ValueMember = "Value"
- Keith
>Mike,
>
>The easiest way to accomplish this, IMHO, is to create a quickie DataTable to use as the Combo's DataSource. Quick code off the top of my head:
>
>DataTable dt = new DataTable();
>dt.Columns.Add("MyDisplay", typeof(string));
>dt.Columns.Add("MyValue", typeof(int));
>
>DataRow row = dt.NewRow();
>row["MyDisplay"] = "One";
>row["MyValue"] = 1;
>dt.Rows.Add(row);
>
>row = dt.NewRow();
>row["MyDisplay"] = "Two";
>row["MyValue"] = 2;
>dt.Rows.Add(row);
>
>// etc.etc.
>
>MyCombo.DataSource = dt;
>MyCombo.DisplayMember = "MyDisplay";
>MyCombo.ValueMember = "MyValue";
>
>
>~~Bonnie
>
>
>
>>Sorry....
>>
>>What I want to do is manually add items to a combobox, where the SelectedItem is One, Two, Three, Four and the SelectedValue is 1,2,3,4. I am having problems figuring this one out...