Solved

Filling a combobox with unique records from dataset

Posted on 2007-04-09
2
235 Views
Last Modified: 2008-02-01
I want to fill in a combobox with unique records from my data set.
        ds = New dsBeamProperties
        ta = New dsBeamPropertiesTableAdapters.tblBeamPropertiesTableAdapter
        ta.Fill(ds.tblBeamProperties)
        Dim i As Integer
        i = 0
        Dim rf As dsBeamProperties.tblBeamPropertiesRow

        For Each rf In ds.tblBeamProperties
            cboBeamTypes.Items.Add(rf.Type)
        Next
0
Comment
Question by:sherrick123
2 Comments
 
LVL 18

Accepted Solution

by:
Priest04 earned 500 total points
ID: 18879326
If you want to populate combbox with non-repeating values, then you should use

" SELECT DISTINCT field_name FROM table_name"

query, when pulling data from a database.

But if you need to retrieve all rows for some other puspose, then you can check if item is already added

if not cboBeamTypes.Items.Contains(rf.Type) then cboBeamTypes.Items.Add(rf.Type)
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 18879580
This absolutely can be done very easy with the following syntax:

'First, instead of declaring rf as the following:
Dim rf As dsBeamProperties.tblBeamPropertiesRow

'Declare rf as a regular DataRow:
Dim rf As System.Data.DataRow

'Use the ToTable method of the DefaultView for the DataTable, and
'     include the "True" parameter for distinct rows, and column names you want returned.
For Each rf In ds.tblBeamProperties.DefaultView.ToTable(True,  "Type").Rows
            cboBeamTypes.Items.Add(rf.Item("Type"))
Next

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now