473,324 Members | 2,002 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,324 software developers and data experts.

Problemos with SQL and ComboBox

Hi there guys!

I'm still having problems with my ComboBox.

I got a table, in SQL, with two columns, ProductID, ProductDescription.

I want to fill a ComboBox with the ProductDescription column, but when the
user selects an item, I want to return the ProductID, so I guess I got to
fill somewhere in the ComboBox the ProductID too.

How could I do this?

Examples are appreciated!!! ;-)

Thanks guys!

Jul 21 '05 #1
2 1117
Cor
Hi Pepehammer,

A sample just changed because I saw a message from Ken

I hope this helps?
Cor

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("Description", System.Type.GetType("System.String"))
dt.Columns.Add("Code", System.Type.GetType("System.Int32"))
Dim i As Integer
For i = 65 To 90
Dim dr As DataRow = dt.NewRow()
dr("Description") = ChrW(i)
dr("Code") = i
dt.Rows.Add(dr)
Next i
Dim dv As DataView = New DataView(dt)
dv.Sort = "Description"
Me.ComboBox2.DisplayMember = "Description"
Me.ComboBox2.ValueMember = "Code"
Me.ComboBox2.DataSource = dv
Me.ComboBox2.SelectedIndex = 5
End Sub

Private Sub ComboBox2_SelectionChangeCommitted _
(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
ComboBox2.SelectionChangeCommitted
MessageBox.Show(Me.ComboBox2.SelectedText & _
" " & Me.ComboBox2.SelectedValue.ToString)
End Sub
///
Jul 21 '05 #2
Thanks very much, it works !!

"Cor" <no*@non.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Hi Pepehammer,

A sample just changed because I saw a message from Ken

I hope this helps?
Cor

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("Description", System.Type.GetType("System.String")) dt.Columns.Add("Code", System.Type.GetType("System.Int32"))
Dim i As Integer
For i = 65 To 90
Dim dr As DataRow = dt.NewRow()
dr("Description") = ChrW(i)
dr("Code") = i
dt.Rows.Add(dr)
Next i
Dim dv As DataView = New DataView(dt)
dv.Sort = "Description"
Me.ComboBox2.DisplayMember = "Description"
Me.ComboBox2.ValueMember = "Code"
Me.ComboBox2.DataSource = dv
Me.ComboBox2.SelectedIndex = 5
End Sub

Private Sub ComboBox2_SelectionChangeCommitted _
(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
ComboBox2.SelectionChangeCommitted
MessageBox.Show(Me.ComboBox2.SelectedText & _
" " & Me.ComboBox2.SelectedValue.ToString)
End Sub
///

Jul 21 '05 #3

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

Similar topics

13
by: Mr. B | last post by:
Here's the situation... You've a combobox with Items already added. Say they look like this (or even lines of text): 10-00-232 10-00-256 10-01-006 10-01-213 10-02-200
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:...
2
by: Pepehammer | last post by:
Hi there guys! I'm still having problems with my ComboBox. I got a table, in SQL, with two columns, ProductID, ProductDescription. I want to fill a ComboBox with the ProductDescription...
2
by: Don | last post by:
I've looked high and low for some code that will allow me to have a combobox with a flat borderstyle. I found a few examples, but nothing that was really usable for me. I had the following...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.