473,387 Members | 1,542 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,387 software developers and data experts.

How to get value of 3rd column in combobox attached to a dataset t

I created a table in a dataset that contains multiple columns. I attached a
combo box to that table. Now I'm doing something wrong with trying to
retrieve the value of the third column of the selecteditem.

The datatable row contains the following columns, (ProductCd, Description,
ProductType), the displaymember is Description, and the valuemember is
ProductCd.

I know how to get the values of the displaymember and valuemember, but how
do I get the value of the ProductType for the selecteditem?

Thanks
Vern
Nov 17 '05 #1
2 11208
I may have found the answers to my own question.

If the combobox is attached to a datatable, then the following seems to work:
DataTable table = (DataTable)combobox1.DataSource;
string textfield =
table.Rows[combobox1.SelectedIndex]["column_name].ToString();

If the combobox is attached to a dataview:
DataView view = (DataView)combobox1.DataSource;
string textfield = view[combobox1.SelectedIndex]["column_name"].ToString();

Let me know if there is a better way.
"Vern" wrote:
I created a table in a dataset that contains multiple columns. I attached a
combo box to that table. Now I'm doing something wrong with trying to
retrieve the value of the third column of the selecteditem.

The datatable row contains the following columns, (ProductCd, Description,
ProductType), the displaymember is Description, and the valuemember is
ProductCd.

I know how to get the values of the displaymember and valuemember, but how
do I get the value of the ProductType for the selecteditem?

Thanks
Vern

Nov 17 '05 #2
I was shown in another newsgroup, a more direct way to get the answer. I had
tried to do this, but wasn't able to get the correct syntax. Anyway, the
combobox stores each row in an object that is retrievable using the
selecteditem property. Here's the code that maps the selecteditem to a
datarowview so it can extract the column data.

sField1.Text =
((DataRowView)sCombobox1.SelectedItem)["ColumnName"].ToString();
"Vern" wrote:
I may have found the answers to my own question.

If the combobox is attached to a datatable, then the following seems to work:
DataTable table = (DataTable)combobox1.DataSource;
string textfield =
table.Rows[combobox1.SelectedIndex]["column_name].ToString();

If the combobox is attached to a dataview:
DataView view = (DataView)combobox1.DataSource;
string textfield = view[combobox1.SelectedIndex]["column_name"].ToString();

Let me know if there is a better way.
"Vern" wrote:
I created a table in a dataset that contains multiple columns. I attached a
combo box to that table. Now I'm doing something wrong with trying to
retrieve the value of the third column of the selecteditem.

The datatable row contains the following columns, (ProductCd, Description,
ProductType), the displaymember is Description, and the valuemember is
ProductCd.

I know how to get the values of the displaymember and valuemember, but how
do I get the value of the ProductType for the selecteditem?

Thanks
Vern

Nov 17 '05 #3

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

Similar topics

27
by: DraguVaso | last post by:
Hi, The Multi column comboBox is a well spoken control, that a lot of people desire, and a lot of people buildtheir own. I tested a lot of them, but none really was what i wanted to have. But...
6
by: Omar | last post by:
When I try to databind my comboBox (specifically field "emplcode") to a filled dataset , the contents of the comboBox displays a bunch of "System.Data.DataRowView". I assume the amount of times...
12
by: Dica | last post by:
i can't seem to find a way to cast the value in my comboBox to integer. i've tried the following: short iProjectID = Convert.ToInt16(cboProjects.SelectedValue); i keep getting a "Sepcified...
1
by: Lasse Eskildsen | last post by:
Hi, I have added a new column to my dataset, but how do I save this to the database? I can only make "Oledbdataadapter.update(dataset)" write rows to the database. Thanks in advance! --
2
by: jaYPee | last post by:
i have search a lot of newsgroup and some website to find a sample for multi column combobox in datagrid but no luck. there are so many sample i found but it is not located in datagrid. i would...
8
by: Myron Marston | last post by:
For a WebService I am developing, I return a DataSet that contains a table listing Field Names and Field Values. The FieldValue column is given the type object becuase it can potentially contain...
1
by: Rob | last post by:
I understand how to populate a list box from a data set... it has a DataSource property... but how do you populate a Textbox with the the contents of a column from a DataSet. FYI - The data set...
3
by: greeknl via AccessMonster.com | last post by:
Is possible to save to a variable in VBA the value a combobox had before it was updated in order to use it because the update value can be retrieved easily Thank you -- Message posted via...
1
by: vgarzon | last post by:
Hi, I'm having issues setting a multi-column combobox in the right way. What I'm trying to do is that when I click on a table (access 2007 subform), a form should fill with the values of the...
0
by: wasim jack | last post by:
sir,I want to change value of combobox of datagridview on the basis of previous combobox value of the same raw of same datagridview
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.