pro_vb thread: Silly listbox question - bear with me.
...I think wrox is messing with me, here's the email I thought I sent
earlier, cut and pasted from my sent folder...
This is what I ended up doing. My State_Cntry_Key is a SQL datatype
int, so it wasn't to much of a stretch to get it into ItemData, and I've
also managed to pull the individual keys out.
Which brings me to one more question, and this ones more of a "best
practices" type question. I have several listboxes similar to this one,
all multiselect type simple. When the user hits submit I'm going to
have to scour my form and pick out all of those ItemData keys. Right
now I'm thinking I'm going to have to do some kind of loop procedure
that looks at each index to determine whether it was selected or not.
Is this the common method, or is there some quick way to dump the
selected items into an array or something.
Thanks,
Jerry
'CODE STARTS HERE
Private Sub Form_Load()
Dim oRs As ADODB.Recordset
Dim arr As Variant 'Array
Set oRs =3D New ADODB.Recordset
With oRs
.ActiveConnection =3D strConn
.Open " Select STate_Cntry_Key, State_Cntry_Name " _
& " from State_Cntry where Area_Key =3D 1 " _
& " Order by State_Cntry_Name " 'Area_Key =3D 1 is the US
PopList .GetRows, lstUS
.Close
End With
End Sub
Private Sub PopList(ByVal arr As Variant, ByRef lstBox As ListBox)
Dim i
For i =3D 0 To UBound(arr, 2)
lstBox.AddItem arr(1, i)
lstBox.ItemData(i) =3D CLng(arr(0, i))
Next
End Sub
'CODE ENDS HERE
-----Original Message-----
From: Duncan [mailto:duncan.faulkner1@b...]
Sent: Wednesday, August 21, 2002 7:23 AM
To: professional vb
Subject: [pro_vb] Re: Silly listbox question - bear with me.
Hi
Yes you would be right, (note to self-read the whole message before
replying)
Duncan
|-----Original Message-----
|From: Vermette, Brett [mailto:brett.vermette@e...]
|Sent: 21 August 2002 13:09
|To: professional vb
|Subject: [pro_vb] Re: Silly listbox question - bear with me.
|
|
|I believe that this will work only when the index values are numeric.
|Alphanumeric values cannot be stored in the itemdata array associated
with
|each listbox. Also, instead of using an explicitly declared index such
as
|"lngIndex" as below, you have the option of using the NewIndex property
|associated with the combo box. The value of NewIndex is equal to the
|ListIndex value of the item most recently added to the ItemData array
|associated with the listbox. It is automatically incremented each time
a
|new item is added to the listbox. The code would look something like
...
|
|combo.itemdata(combo.newindex) =3D rs("fieldname2")
|
|Let me know if I am incorrect in my understanding that only numeric
values
|can be contained in the ItemData array.
|
|my 1.5 cents worth ...
|
|Brett
|
|-----Original Message-----
|From: Duncan [mailto:duncan.faulkner1@b...]
|Sent: Wednesday, August 21, 2002 4:33 AM
|To: professional vb
|Subject: [pro_vb] Re: Silly listbox question - bear with me.
|
|
|Hi
| Rather than create an array, why not use the Itemdata property of the
|combobox, so where the line: arr(combo.listindex)=3Drs("fieldname2")
|use instead: combo.itemdata(lngIndex) =3D rs.fields("fieldname2").value
|
|you will need to dim lngindex as long and set it to lngIndex =3D -1 in
the
|procedure and increament it by one each time round, ie
lngindex=3DlngIndex+1
|
|this way the array is associated with that combo box and nothing else.
|
|my two cents worth
|Duncan
|MCP,MCSD,AMIAP
|
||-----Original Message-----
||From: Satyajeet Hattangadi [mailto:satyajh@m...]
||Sent: 21 August 2002 06:21
||To: professional vb
||Subject: [pro_vb] Re: Silly listbox question - bear with me.
||
||
||add a sub called popcombo taht populates the combo
||
||pseudo code...
||
||Option explicit
||dim cmbarr(0)
||sub popcombo
|| open recordset..
||while not rs.eof
|| redim the array
|| combo1.additem rs("fieldname")
|| arr(combo.listindex)=3Drs("fieldname2")
||wend
||
||end sub
||
||sp now you have populated the combo and have an array soociated with
it so
||arr(combo1.listindex) will hold value asssociated with the item and
||combo1.text will hold the text to be displayed.
||i.e. combo1.text may show "New Delhi" and arr(combo1.listindex) will
hold
||"ND"
||
||i guess this is what you are tring to achieve right??
||HTH
||satya
||
||----- Original Message -----
||From: "Jerry Diegel" <diegelj@g...>
||To: "professional vb" <pro_vb@p...>
||Sent: Tuesday, August 20, 2002 9:02 PM
||Subject: [pro_vb] Silly listbox question - bear with me.
||
||
||> I want to populate a listbox with State and Country names I'm
||pulling from
||my database. My query is...
||>
||> Select State_Cntry_Key, State_Cntry_Name from State
||>
||> I've managed to populate the listbox with the text I need, but
|I'm having
||trouble associating the key with the text. The listbox wants the
||index from
||0 to n, while I just want my text displayed in alphabetical
|order, with the
||key stored like the VALUE property of an HTML listbox. So, I'm
looking at
||three things.
||>
||> One, someone tell me the stupid little detail I'm missing that
|makes this
||easy.
||> Two, point me two another component that works the same as a
|listbox with
||this added feature.
||> Three, tell me to create a public array and use it to associate the
||listbox index with the State_Cntry_Key.
||>
||> Any advice would be appreciated.
||>
||> Thanks,
||>
||> Jerry
||>
||>
||> ---
||> Visual C# - A Guide for VB6 Developers
||> This book will make it easy to transfer your skills
||> from Visual Basic 6 to C#, the language of choice
||> of the .NET Framework.
||> http://www.wrox.com/ACON11.asp?ISBN=3D1861007175&p2p0059
||>
||>
||
||
||---
||Outgoing mail is certified Virus Free.
||Checked by AVG anti-virus system (http://www.grisoft.com).
||Version: 6.0.361 / Virus Database: 199 - Release Date: 07/05/2002
||
||*********************************************************
||Disclaimer
||
||This message (including any attachments) contains
||confidential information intended for a specific
||individual and purpose, and is protected by law.
||If you are not the intended recipient, you should
||delete this message and are hereby notified that
||any disclosure, copying, or distribution of this
||message, or the taking of any action based on it,
||is strictly prohibited.
||
||*********************************************************
||Visit us at http://www.mahindrabt.com
||
||
||---
||Visual C# - A Guide for VB6 Developers
||This book will make it easy to transfer your skills
||from Visual Basic 6 to C#, the language of choice
||of the .NET Framework.
||http://www.wrox.com/ACON11.asp?ISBN=3D1861007175&p2p0059
||
||
|
|
|
|---
|Visual C# - A Guide for VB6 Developers
|This book will make it easy to transfer your skills
|from Visual Basic 6 to C#, the language of choice
|of the .NET Framework.
|http://www.wrox.com/ACON11.asp?ISBN=3D1861007175&p2p0059
|
|
|
|---
|Visual C# - A Guide for VB6 Developers
|This book will make it easy to transfer your skills
|from Visual Basic 6 to C#, the language of choice
|of the .NET Framework.
|http://www.wrox.com/ACON11.asp?ISBN=3D1861007175&p2p0059
|
|
---
Visual C# - A Guide for VB6 Developers
This book will make it easy to transfer your skills
from Visual Basic 6 to C#, the language of choice
of the .NET Framework.
http://www.wrox.com/ACON11.asp?ISBN=3D1861007175&p2p0059