Link to home
Start Free TrialLog in
Avatar of sanlorenzo
sanlorenzo

asked on

Visual Studio 2008 Populate a Combo Box with Distinct Values

I have a Visual Studio 2008 Form  

i have called frm_1

On the Form a have a Combo Box
i have called cbo_1

i have a dataset

i have called dataset1

 link to a Table

i have called the table tbl_1

the Table have 4 Collums : ID_Name / Name / City / State /

I want use the Combo Box to pass a parameter to a Query  that i want to develop

The query will  filter by State ( but this question do not involve the Query , it related on how populate the Combo Box )
So what is the code to fill the cbo_1 with the States listed into the tbl_1 ( linked to the dataset1???

so the cbo_1 should list the state ( as unique value ) i mean i want be able to
Have unique state list on cbo_1
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi sanlorenzo;

I am assuming that you have the latest SP for Visual Studio 2008. You can use Linq to Object to create a list to feed the ComboBox as follows.

Dim stateList = (From t in tbl_1.AsEnumerable()
                 Select t.Field(Of String)("States")).Distinct().ToList()
			           
cbo_1.DataSource = stateList

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jesus Rodriguez
Jesus Rodriguez
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial