Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: RE: List/Combo question: Display one (text) field, b ut store another


Message #1 by "Pardee, Roy E" <roy.e.pardee@l...> on Mon, 17 Sep 2001 12:17:28 -0700
In case anybody's interested, I did go ahead & get that ActiveX control
together.  The ocx and/or the source code can be found at my web page:
http://members.home.net/r.pardee/ --click the link "Multi Column Combo Box".

Cheers,

-Roy

-----Original Message-----
From: Pardee, Roy E [mailto:roy.e.pardee@l...]
Sent: Thursday, August 30, 2001 3:58 PM
To: professional vb
Subject: [pro_vb] RE: List/Combo question: Display one (text) field, but
store another


Ah, now that's clever--thank you.  And thanks also to Judith & Nigel also
for your responses.

I'm actually this close to just biting the bullet & developing my own
ActiveX control that will take a disconnected recordset & have it populate a
combo box,, expose a Columns collection & a BoundColumn property & set it
all up to work just like I want...

Thanks again to all!

Cheers,

-Roy

-----Original Message-----
From: Zadoyen, Eva [mailto:EZadoyen@s...]
Sent: Thursday, August 30, 2001 10:51 AM
To: professional vb
Subject: [pro_vb] RE: List/Combo question: Display one (text) field, b
ut s tore another


Also, you may use hidden combo box and fill it with the CustomerCode 

 While Not rs.EOF
  comboName.addItem rs.Fields("CustomerName")
  comboCode.addItem rs.Fields("CustomerCode")
  rs.MoveNext
 Wend
    When user select Name from the  comboName - select the same  Listindex
for comboCode


Eva
-----Original Message-----
From: Nigel Parker [mailto:Nigel.Parker@c...]
Sent: Thursday, August 30, 2001 12:21 PM
To: professional vb
Subject: [pro_vb] RE: List/Combo question: Display one (text) field, but
s tore another


Hi Roy

If you display the CustomerName in the combo
and would really like to use the CustomerNumber behind the scenes
then you could load an array with the NewIndex as the array index and the
string CustomerNumber as the contents at that index.

*If the CustomerNumber was numeric and within the range of an integer
you would add it to the combo1.ItemData property.
The ItemData is an   array associated with the combo and is useful
when you need to display text but hold an integer value against that text
value.

eg
 Dim theArray() as String

 combo1.Clear 'empty the combo
 Erase theArray() 'clear the array

 While Not rs.EOF
  combo1.addItem rs.Fields("CustomerName")
  ReDim Preserve theArray(combo1.NewIndex)
  theArray(combo1.NewIndex) = rs.Fields("CustomerNumber")
  rs.MoveNext
 Wend

when a user selects the combo ( CustomerName) you can get the CustomerNumber
for that customer from the  array.

Both the array and the combo default to having their lower bounds to zero.

Dont forget to make a check on the combo1.ListIndex being minus 1!

eg
this code would be placed in the Combo1_Click event
*provided that the combo was a drop down list

 'form level customer reference
 Dim m_ strCustNumber as String

 If combo1.ListIndex <> -1 then
  m_strCustNumber = theArray(combo1.ListIndex)
 End If

Is this what you are looking for?

Nigel


> -----Original Message-----
> From: Pardee, Roy E [SMTP:roy.e.pardee@l...]
> Sent: Thursday, August 30, 2001 4:07 PM
> To: professional vb
> Subject: [pro_vb] List/Combo question: Display one (text) field, but
> store     another
> 
> Greetings all,
> 
> Many thanks to everybody who replied to my earlier question re: hooking up
> a
> list or combo box to a disconnected recordset--it seems that looping
> through
> the rs while calling .AddNew is the easiest method.
> 
> Here's my next question--this control needs to store a database field
> called
> CustomerNumber, which is a text field containing some alphanumeric data
> (e.g., "1010-REP").  I would like to display the CustomerName field
> instead
> of CustomerNumber, since that's primarily how my users will recognize
> customers.
> 
> It looks to me like this is not possible with VB's list or combo box
> controls--you can sort of fake it if your hidden field values are numerics
> w/in the range of an Integer (you just store the .Index property instead
> of
> the .Text property) but if you've got two text fields, you're out of luck.
> Can anybody (dis)confirm this for me?  If I'm wrong, how do you do it & if
> I'm right, is there a decent way to get the same functionality?  (It's
> trivially simple in Access!  Half my kingdom for an Access combo box! 8^)
> 
> One thing I've looked into & don't like so far is the ListView control.
> This thing does multiple columns quite well, but it doesn't seem to have
> anything like a .Text property I could easily read or set programmatically
> (do you really have to loop through the entire collection of ListItems
> looking for one whose .Selected property is True?).  Here again my
> ignorance
> could be making me think this is harder than it really is & I'd love to
> have
> your advice...
> 
> Thanks!
> 
> -Roy
> 
> Roy Pardee
> Programmer/Analyst


  Return to Index