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

ComboBox HELP Pleasse!

D
I am using the following code as an example. Once the user selects an
item from the combobox (e.g., "Martin"), how can I access the value of
that item (e.g., "1")?

Dim dtAdjuster as new DataTable
dtAdjuster.Columns.add("Names")
dtAdjuster.Columns.add("Keys")
dtAdjuster.loaddatarow(new object() {"Martin", "1"},true)
dtAdjuster.loaddatarow(new object() {"Cor","2"},true)

Combobox1.datasource = dt
Combobox1.displaymember = "Names"
Combobox1.Valuemember = "Keys"

In the click method, I check the value of

Combobox1.SelectedValue.ToString

It is returning "System.Data.DataRowView" as the value of the
item. What is wrong? Any idea?

Thank you in advance.

Feb 23 '06 #1
5 944
You are missing the key component of code that involves databinding. You
must call the DataBind() method after setting the DataSource property. In
your case, it looks like you need the following line:

Combobox1.DataBind()

I think this will fix your problem, if not, let me know. Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"D" <D@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
I am using the following code as an example. Once the user selects an
item from the combobox (e.g., "Martin"), how can I access the value of
that item (e.g., "1")?

Dim dtAdjuster as new DataTable
dtAdjuster.Columns.add("Names")
dtAdjuster.Columns.add("Keys")
dtAdjuster.loaddatarow(new object() {"Martin", "1"},true)
dtAdjuster.loaddatarow(new object() {"Cor","2"},true)

Combobox1.datasource = dt
Combobox1.displaymember = "Names"
Combobox1.Valuemember = "Keys"

In the click method, I check the value of

Combobox1.SelectedValue.ToString

It is returning "System.Data.DataRowView" as the value of the
item. What is wrong? Any idea?

Thank you in advance.

Feb 23 '06 #2
D,

In what *event* are you using to get that selectedvalue.

Cor
Feb 23 '06 #3
Nathan,

The DataBind is typical a webform method. A webform does not have a combobox
luckily for that they have named that a little bit the same control
DropDownList.

I hope this helps,

Cor
Feb 23 '06 #4
D,

I copied and pasted your code into a VS 2003 Windows Form application. After
fixing 1 typo, your code worked for me. I changed this line:

Combobox1.datasource = dt

to this line:

ComboBox1.DataSource = dtAdjuster

Kerry Moorman
"D" wrote:
I am using the following code as an example. Once the user selects an
item from the combobox (e.g., "Martin"), how can I access the value of
that item (e.g., "1")?

Dim dtAdjuster as new DataTable
dtAdjuster.Columns.add("Names")
dtAdjuster.Columns.add("Keys")
dtAdjuster.loaddatarow(new object() {"Martin", "1"},true)
dtAdjuster.loaddatarow(new object() {"Cor","2"},true)

Combobox1.datasource = dt
Combobox1.displaymember = "Names"
Combobox1.Valuemember = "Keys"

In the click method, I check the value of

Combobox1.SelectedValue.ToString

It is returning "System.Data.DataRowView" as the value of the
item. What is wrong? Any idea?

Thank you in advance.

Feb 23 '06 #5
Kerry,

It was some sample code I made, I did not see this one change.
(I don't see the reason, this is the only change I use forever dt)

Good catch,

:-)

Cor

"Kerry Moorman" <Ke**********@discussions.microsoft.com> schreef in bericht
news:B0**********************************@microsof t.com...
D,

I copied and pasted your code into a VS 2003 Windows Form application.
After
fixing 1 typo, your code worked for me. I changed this line:

Combobox1.datasource = dt

to this line:

ComboBox1.DataSource = dtAdjuster

Kerry Moorman
"D" wrote:
I am using the following code as an example. Once the user selects an
item from the combobox (e.g., "Martin"), how can I access the value of
that item (e.g., "1")?

Dim dtAdjuster as new DataTable
dtAdjuster.Columns.add("Names")
dtAdjuster.Columns.add("Keys")
dtAdjuster.loaddatarow(new object() {"Martin", "1"},true)
dtAdjuster.loaddatarow(new object() {"Cor","2"},true)

Combobox1.datasource = dt
Combobox1.displaymember = "Names"
Combobox1.Valuemember = "Keys"

In the click method, I check the value of

Combobox1.SelectedValue.ToString

It is returning "System.Data.DataRowView" as the value of the
item. What is wrong? Any idea?

Thank you in advance.

Feb 23 '06 #6

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

Similar topics

7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
1
by: anonymous | last post by:
I've been trying to put a them, please help me out. Here's the major parts of my code: public Form1() { DataSet myDataSet = new DataSet("myDataSet"); DataTable testTable = new...
3
by: TT (Tom Tempelaere) | last post by:
Hay there, I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one (I hope .NET 2.0 supplies one). I based it on this article:...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.