Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding items to combobox
Message
From
03/10/2005 09:45:01
Keith Payne
Technical Marketing Solutions
Florida, United States
 
 
To
03/10/2005 00:53:57
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
01054999
Message ID:
01055493
Views:
19
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...
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform