Solved

Filling a combobox with unique records from dataset

Posted on 2007-04-09
2
233 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

11 Experts available now in Live!

Get 1:1 Help Now