473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Populating a combobox from dataset

I am a beginner and learning VB.net

There are two wasy to bind a combobox or a listbox
First approach is to assign a datasource and displaymember
Second approach is to iterate through datarow collection

This works
With ComboPaymentType
.DataSource = dsComboItems.Tables("PaymentType")
.DisplayMember = "PaymentType"
.ValueMember = "PaymentTypeID"
End With

The second approach
Dim row As DataRow 'Represents a row of data in Systems.data.datatable
For Each row In dsComboItems.Tables("PaymentType").Rows
ComboPaymentType.Items.Add(row("PaymentType"))
Next

How to assign value propery (in my case "paymenttypeId" property as a
value of the combobox item) in the second approach?

Apr 16 '06 #1
4 35244
The ValueMember is only available to you when you bind. The trick to adding
the extra record in reference to your previous post is to add it to your
datatable instead of your combo box since it's getting it's data from there.
So long as you don't do a save on your datatable then you don't have to
worry about screwing up data in the table you are selecting the data from.

"c_shah" <sh*********@netzero.net> wrote in message
news:11*********************@g10g2000cwb.googlegro ups.com...
I am a beginner and learning VB.net

There are two wasy to bind a combobox or a listbox
First approach is to assign a datasource and displaymember
Second approach is to iterate through datarow collection

This works
With ComboPaymentType
.DataSource = dsComboItems.Tables("PaymentType")
.DisplayMember = "PaymentType"
.ValueMember = "PaymentTypeID"
End With

The second approach
Dim row As DataRow 'Represents a row of data in Systems.data.datatable
For Each row In dsComboItems.Tables("PaymentType").Rows
ComboPaymentType.Items.Add(row("PaymentType"))
Next

How to assign value propery (in my case "paymenttypeId" property as a
value of the combobox item) in the second approach?

Apr 16 '06 #2
>>
The ValueMember is only available to you when you bind

Does that mean I can only use value member property when i bind my
combobox to the dataset using data source? and I can't use value member
property when I iterate through the datarow collection in order to
populate combobox.

I am SQL DBA and started to learnVB.net so sorry about this newbie
questions...
in reference to your previous post

Thank you for elaborating this..actually I can add default item
(--select from combobox--) in the second approach easily by
combobox.items.insert(0,"--select from combobox--") but was not sure
how to get value property.

Apr 16 '06 #3
C_Sjah,

Your first method is binding the properties from the datatable to the
properties from the combobox.

Your second method is filling up a combobox with values, so you can handle
those, for the same sake you just had added some values..

Therefore the first is binding, the second has nothing to do with that.

I hope this helps,

Cor

"c_shah" <sh*********@netzero.net> schreef in bericht
news:11*********************@g10g2000cwb.googlegro ups.com...
I am a beginner and learning VB.net

There are two wasy to bind a combobox or a listbox
First approach is to assign a datasource and displaymember
Second approach is to iterate through datarow collection

This works
With ComboPaymentType
.DataSource = dsComboItems.Tables("PaymentType")
.DisplayMember = "PaymentType"
.ValueMember = "PaymentTypeID"
End With

The second approach
Dim row As DataRow 'Represents a row of data in Systems.data.datatable
For Each row In dsComboItems.Tables("PaymentType").Rows
ComboPaymentType.Items.Add(row("PaymentType"))
Next

How to assign value propery (in my case "paymenttypeId" property as a
value of the combobox item) in the second approach?

Apr 16 '06 #4
You need to separate your concept of a datatable and the combo box, it
appears to be confusing you. You are correct in that you can add items to
the combo box, but unless you bind it you can't really use the valuemember.
When binding to a table you must have 2 columns, one for Display and another
for Value or if not the DisplayMember will take place of the ValueMember.
In your example, you're not really adding a default item, what you're really
doing is inserting an item at index 0, the very first item. If you only
have a Display member and want to populate the control manually then
reference those items, you can get the value this way:
ComboBox1.Items.Item(ItemNo) or the currently selected item: ComboBox1.Text
"c_shah" <sh*********@netzero.net> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
The ValueMember is only available to you when you bind
Does that mean I can only use value member property when i bind my
combobox to the dataset using data source? and I can't use value member
property when I iterate through the datarow collection in order to
populate combobox.

I am SQL DBA and started to learnVB.net so sorry about this newbie
questions...
in reference to your previous post

Thank you for elaborating this..actually I can add default item
(--select from combobox--) in the second approach easily by
combobox.items.insert(0,"--select from combobox--") but was not sure
how to get value property.

Apr 16 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Juan | last post by:
When populating a dataset I get an error if the data being retrieved includes a string field with a Null value: "Not valid store type: DBNull". What kinf of data type can i define in the dataset to...
0
by: amber | last post by:
I've been trying to figure out how to get 2 datasets to populate a report/subreport - and I think I'm on the right track...just having a few problems somewhere... I have created a dataset (.xsd)...
1
by: Steve | last post by:
C# How do I populate a row in a dataset ? I have created a class called Job. In this class I have a few methods such as CreateJob and FetchJob. FetchJob returns a DataSet of the Job table. The...
1
by: Rob via .NET 247 | last post by:
Ok, I'm new to .NET so I'm afraid I'm doing something stupidhere, but I'm trying to populate a DataSet manually from aDataReader, and its turning out to be ridiculously difficult. Yes, I could use...
8
by: Lumpierbritches | last post by:
thank you in advance for any and all assistance. I'm trying to populate a combobox with a table in VB.Net. Table Name: tblBreed cboBreed Thank you again. Michael
0
by: John | last post by:
Hi all, I'm calling a stored proc which does 4 "selects" and then I populate a dataset looping through the dr using a dr.NextResult() but the stored proc may not return any results for one or...
0
by: sanalsuryakalady | last post by:
Hello All, I have 2 combo box in ASP.NET 1.1. When ever I change the value in one combo the other combo will be loaded with the new values using XMLHTTP.But when I post back the screen I lose the...
0
JordanMartz
by: JordanMartz | last post by:
''' <summary> ''' Populates the DataGridView ''' </summary> Private Sub PopulateDataGridView() ' Set the column header names. userAccessGrid.ColumnCount = 5 ...
6
by: buterfly0707 | last post by:
hi.. i want to fill my combobox from the values which im having in my table in the database. and my combobox name is combobox1 and my table is tblDetails, and this table having two columns code...
4
by: prashantdixit | last post by:
Hi, I have imported huge log file (35 MB size) into a worksheet. One of its column contain some data. There is a Main Sheet which contains "ComboBoxStartTime" ActiveX Combo control. I am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.