473,385 Members | 1,317 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.

Combo and SelectedValue

Hi

I have a standard combo on a WinForm and use the following code to bind it
to a datatable (X returns a datatable object)

Dim X As New BusinessRules.Contracts.Agreements

With cmbAgreement
.DataSource = X.AgreementsByCustomer(66524)
.ValueMember = ("AgreementID")
.DisplayMember = ("Name")
End With

The list is populated correctly, however when the user selects a record I
want to retrieve the "AgreementID" of the "Name" selected.

The value of cmbAgreement.Text is what the user selected but
cmbAgreement.SelectedValue is always Nothing and .SelectedText is always " ".

How can I retrieve the "AgreementID" ?

Jan 4 '06 #1
3 1721
Your code looks correct to me. Not sure why you are doing this:
.ValueMember = ("AgreementID")
.DisplayMember = ("Name")
instead of simply this, but it seems to still work either way. .ValueMember = "AgreementID"
.DisplayMember = "Name"
http://samples.gotdotnet.com/quickst...FormsData.aspx

Not sure what is going wrong with your code. Same sort of code seems to work
fine for me:

Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted

Debug.Print(ComboBox1.SelectedText)
Debug.Print(ComboBox1.SelectedValue.ToString)

End Sub

Greg
"Stephen Ritchie" <St************@discussions.microsoft.com> wrote in
message news:28**********************************@microsof t.com... Hi

I have a standard combo on a WinForm and use the following code to bind it
to a datatable (X returns a datatable object)

Dim X As New BusinessRules.Contracts.Agreements

With cmbAgreement
.DataSource = X.AgreementsByCustomer(66524)
.ValueMember = ("AgreementID")
.DisplayMember = ("Name")
End With

The list is populated correctly, however when the user selects a record I
want to retrieve the "AgreementID" of the "Name" selected.

The value of cmbAgreement.Text is what the user selected but
cmbAgreement.SelectedValue is always Nothing and .SelectedText is always "
".

How can I retrieve the "AgreementID" ?

Jan 4 '06 #2
Hi Greg

Thanks for the response, however removing the (), or putting code within the
SelectionChangeCommitted event has had any effect - I am completely baffled
!!!!

One thing I have noticed is within the SelectionChangeCommitted event the
Datasource property is now Nothing (??).

Would this have an effect ?

Stephen

"Greg Burns" wrote:
Your code looks correct to me. Not sure why you are doing this:
.ValueMember = ("AgreementID")
.DisplayMember = ("Name")


instead of simply this, but it seems to still work either way.
.ValueMember = "AgreementID"
.DisplayMember = "Name"


http://samples.gotdotnet.com/quickst...FormsData.aspx

Not sure what is going wrong with your code. Same sort of code seems to work
fine for me:

Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted

Debug.Print(ComboBox1.SelectedText)
Debug.Print(ComboBox1.SelectedValue.ToString)

End Sub

Greg
"Stephen Ritchie" <St************@discussions.microsoft.com> wrote in
message news:28**********************************@microsof t.com...
Hi

I have a standard combo on a WinForm and use the following code to bind it
to a datatable (X returns a datatable object)

Dim X As New BusinessRules.Contracts.Agreements

With cmbAgreement
.DataSource = X.AgreementsByCustomer(66524)
.ValueMember = ("AgreementID")
.DisplayMember = ("Name")
End With

The list is populated correctly, however when the user selects a record I
want to retrieve the "AgreementID" of the "Name" selected.

The value of cmbAgreement.Text is what the user selected but
cmbAgreement.SelectedValue is always Nothing and .SelectedText is always "
".

How can I retrieve the "AgreementID" ?


Jan 5 '06 #3
Sorted !!!!!!!!!!

Need to do Ctype the value to an Integer (as AgreementID is an integer
value) so the following worked

MessageBox.Show("Selected value is " & CType(cmbAgreement.SelectedValue,
Integer))

:)

"Stephen Ritchie" wrote:
Hi

I have a standard combo on a WinForm and use the following code to bind it
to a datatable (X returns a datatable object)

Dim X As New BusinessRules.Contracts.Agreements

With cmbAgreement
.DataSource = X.AgreementsByCustomer(66524)
.ValueMember = ("AgreementID")
.DisplayMember = ("Name")
End With

The list is populated correctly, however when the user selects a record I
want to retrieve the "AgreementID" of the "Name" selected.

The value of cmbAgreement.Text is what the user selected but
cmbAgreement.SelectedValue is always Nothing and .SelectedText is always " ".

How can I retrieve the "AgreementID" ?

Jan 5 '06 #4

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

Similar topics

4
by: mr_burns | last post by:
hi, using javascript, how do i select an option in a combo box? i have tried looking on the internet but dont really know what i should be searching for. what i want to happen is that when a...
16
by: Mike L | last post by:
This is for a Win form. My combo box DropDownStyle is set to simple. When the user types in a 3 character string in the combo box, the closest item in the collection is shown, right below where...
1
by: Young J. Putt | last post by:
I have what I thought was a relatively simple data situation that I can't seem to get working using ADO.NET datasets and data binding. I have an "Issues" table which records the UserID of the user...
1
by: James | last post by:
I am used to VB6 but need to develop something in .Net. I need to create several bound combo-boxes which will use lookup tables to get their values. I created a form using the dataform wizard....
2
by: Nikolay Petrov | last post by:
I have asked a question before some time, and a guy responded to it. His answer raised new questions and I replied them back, but still no answer. I need them urgently so I am to post the whole...
2
by: http://www.visual-basic-data-mining.net/forum | last post by:
Hi... Say i have this string call "data" in Form1, this string contains number "5" value.... how do i pass this string to the Form2 and compare with the combo box items... The combo box ...
6
by: Jean Christophe Avard | last post by:
Hi! I'm designing an application that produces invoices. I have a combobox that is populated with the Name of every client in the database. What I would like to do is to have the combobox to...
4
by: Mark L. Breen | last post by:
Hello Guys and Galls, I use combos on my forms. The code to initialise the combos is as follows Dim dsPIDTypes As DataSet dsPIDTypes = PartDB.GetPIDTypes ' Returns a dataset object...
9
by: Kay | last post by:
Hi all, Could you tell me the best way to add a blank item(as first item) in a data binded combo box? Because I think I didn't do it right and it generate an error if the second item(after the...
3
by: Bill | last post by:
I have what I think should be a simple question regarding a bound combo box. My first table is Dealers: DealerID - primary key DealerName BillToLocation My second table is Locations:...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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?
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
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...

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.