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
Solved

Filling a combobox with unique records from dataset

Posted on 2007-04-09
2
241 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

860 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