Solved

Filling a combobox with unique records from dataset

Posted on 2007-04-09
2
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
System.net.Sockets Error 5 48
MYSQL responding very slow 3 65
Need help converting bitmap to image in VB.Net 8 64
vb.net background worker crossthread 11 42
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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