Groups | Blog | Home
all groups > vb.net data > december 2004 >

vb.net data : Combo Box Listing Category


Jeremy Dillinger
12/3/2004 12:29:25 AM
I have a program setup to pull data from a database. My database table has
things such as (category, Item, price, etc.) In my program I want to have
multiple list boxes that will have a pull down list of different categories.

The category is stored as a number and the item is stored as a string. Also
once the item is picked from the list I would also like to extract the price
corresponding to the chosen item. How would I go about doing something like
this. Thanks for your help!

Jeremy

Mona \(Grapecity\)
12/3/2004 11:38:12 AM
This is a multi-part message in MIME format.

------=_NextPart_000_004F_01C4D92C.9210F5F0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi Jeremy,

In your application, as you just need to diaplay the price,a label or a =
diabled text box would be a better option than a listbox.I'm sending you =
a snippet of code to load a list box and display corresponding =
details.You can use the same logic to check the condition for the item =
in second listbox
Dim ocmd As New OleDb.OleDbCommand

Dim strcon As String

Dim oDR As OleDb.OleDbDataReader

strcon =3D "Provider =3D Microsoft.Jet.OLEDB.4.0;Data =
Source=3DC:\db3.mdb;Persist Security Info=3DFalse"

ocmd.Connection =3D New OleDb.OleDbConnection(strcon)

ocmd.Connection.Open()

ocmd.CommandText =3D "Select CompanyName from Customers"

oDR =3D ocmd.ExecuteReader(CommandBehavior.SequentialAccess)

Do While oDR.Read

ListBox1.Items.Add(oDR.Item("CompanyName"))

Loop



If oDR.Read() Then

With oDR

txtCompName.Text =3D .Item("CompanyName").ToString()

txtContact.Text =3D _

..Item("ContactName").ToString()

txtDate.Text =3D _

..Item("BirthDate").ToString()

txtAddress.Text =3D _

..Item("Address").ToString()

End With

End If

oDR.Close()

'oCmd.Connection.Close()

HTH

Mona

[quoted text, click to view]
------=_NextPart_000_004F_01C4D92C.9210F5F0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1476" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi Jeremy,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>In your application, as you just need =
to diaplay=20
the price,a label or a diabled text box would be a better option than a=20
listbox.I'm sending you a snippet of code to load a list box and display =

corresponding details.You can use the same logic to check the condition =
for the=20
item in second listbox</FONT></DIV>
<DIV>
<P><FONT face=3DArial size=3D2>Dim ocmd As New =
OleDb.OleDbCommand</FONT></P>
<P><FONT face=3DArial size=3D2>Dim strcon As String</FONT></P>
<P><FONT face=3DArial size=3D2>Dim oDR As =
OleDb.OleDbDataReader</FONT></P></DIV>
<DIV>
<P><FONT face=3DArial size=3D2>strcon =3D "Provider =3D =
Microsoft.Jet.OLEDB.4.0;Data=20
Source=3DC:\db3.mdb;Persist Security Info=3DFalse"</FONT></P>
<P><FONT face=3DArial size=3D2>ocmd.Connection =3D New=20
OleDb.OleDbConnection(strcon)</FONT></P>
<P><FONT face=3DArial size=3D2>ocmd.Connection.Open()</FONT></P>
<P><FONT face=3DArial size=3D2>ocmd.CommandText =3D "Select CompanyName =
from=20
Customers"</FONT></P>
<P><FONT face=3DArial size=3D2>oDR =3D=20
ocmd.ExecuteReader(CommandBehavior.SequentialAccess)</FONT></P>
<P><FONT face=3DArial size=3D2>Do While oDR.Read</FONT></P>
<P><FONT face=3DArial=20
size=3D2>ListBox1.Items.Add(oDR.Item("CompanyName"))</FONT></P>
<P><FONT face=3DArial size=3D2>Loop</FONT></P>
<P><FONT face=3DArial size=3D2></FONT>&nbsp;</P>
<P><FONT face=3DArial size=3D2>If oDR.Read() Then</FONT></P>
<P><FONT face=3DArial size=3D2>With oDR</FONT></P>
<P><FONT face=3DArial size=3D2>txtCompName.Text =3D=20
..Item("CompanyName").ToString()</FONT></P>
<P><FONT face=3DArial size=3D2>txtContact.Text =3D _</FONT></P>
<P><FONT face=3DArial =
size=3D2>.Item("ContactName").ToString()</FONT></P>
<P><FONT face=3DArial size=3D2>txtDate.Text =3D _</FONT></P>
<P><FONT face=3DArial size=3D2>.Item("BirthDate").ToString()</FONT></P>
<P><FONT face=3DArial size=3D2>txtAddress.Text =3D _</FONT></P>
<P><FONT face=3DArial size=3D2>.Item("Address").ToString()</FONT></P>
<P><FONT face=3DArial size=3D2>End With</FONT></P>
<P><FONT face=3DArial size=3D2>End If</FONT></P>
<P><FONT face=3DArial size=3D2>oDR.Close()</FONT></P>
<P><FONT face=3DArial size=3D2>'oCmd.Connection.Close()</FONT></P>
<P><FONT face=3DArial size=3D2>HTH</FONT></P>
<P><FONT face=3DArial size=3D2>Mona</FONT></P></DIV>
<DIV><FONT face=3DArial size=3D2>"Jeremy Dillinger" &lt;</FONT><A=20
href=3D"mailto:jerdill@hotmail.com"><FONT face=3DArial=20
size=3D2>jerdill@hotmail.com</FONT></A><FONT face=3DArial size=3D2>&gt; =
wrote in=20
message </FONT><A =
href=3D"news:u9jBZhP2EHA.804@TK2MSFTNGP12.phx.gbl"><FONT=20
face=3DArial =
size=3D2>news:u9jBZhP2EHA.804@TK2MSFTNGP12.phx.gbl</FONT></A><FONT=20
face=3DArial size=3D2>...</FONT></DIV><FONT face=3DArial size=3D2>&gt; I =
have a program=20
setup to pull data from a database. My database table has<BR>&gt; things =
such as=20
(category, Item, price, etc.) In my program I want to have<BR>&gt; =
multiple list=20
boxes that will have a pull down list of different categories.<BR>&gt; =
<BR>&gt;=20
The category is stored as a number and the item is stored as a string.=20
Also<BR>&gt; once the item is picked from the list I would also like to =
extract=20
the price<BR>&gt; corresponding to the chosen item. How would I go about =
doing=20
something like<BR>&gt; this. Thanks for your help!<BR>&gt; <BR>&gt;=20
Jeremy<BR>&gt; <BR>&gt; </FONT></BODY></HTML>

------=_NextPart_000_004F_01C4D92C.9210F5F0--
Jeremy Dillinger
12/3/2004 8:17:04 PM
This is a multi-part message in MIME format.

------=_NextPart_000_01AE_01C4D975.0EFB2E80
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Thanks for the code.. but I don't think it was quite what I was looking =
for. When I said listbox I really meant Combo box sorry about that. I am =
trying to make this be like a dropdown menu of one category then display =
the price of the selected item from the combo box in a textbox next to =
it.

This program will be to custom build a computer. So for example. I want =
one combo box to have a list of Motherboards to choose from and then =
once the board is chosen show the price of it next to it. Then below =
that I want another combobox that will have a list of Processors and =
then show the price of that. I would like it to show this for all the =
categories out of the database. I hope this makes more sense. Thanks!

Jeremy
------=_NextPart_000_01AE_01C4D975.0EFB2E80
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1458" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Thanks for the code.. but I don't think =
it was=20
quite what I was looking for. When I said listbox I really meant Combo =
box sorry=20
about that. I am trying to make this be like a dropdown menu of one =
category=20
then display the price of the selected item from the combo box in a =
textbox next=20
to it.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>This program will be to custom build a =
computer. So=20
for example. I want one combo box to have a list of Motherboards to =
choose from=20
and then once the board is chosen show the price of it next to it. Then =
below=20
that I want another combobox that will have a list of Processors and =
then show=20
the price of that. I would like it to show this for all the categories =
out of=20
the database. I hope this makes more sense. Thanks!</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Jeremy</FONT></DIV></BODY></HTML>

------=_NextPart_000_01AE_01C4D975.0EFB2E80--
AddThis Social Bookmark Button