Listbox issue

  • Thread starter Thread starter Fabio
  • Start date Start date
F

Fabio

Hi all,

How can I hide an id column in the listbox and the combobox???

I'm puting the PK into the text, like this:

Books(1)
CD(2)

how can I hide these codes???

Thanks in advance,

Fábio Augusto
 
* "Fabio said:
How can I hide an id column in the listbox and the combobox???

I'm puting the PK into the text, like this:

Books(1)
CD(2)

how can I hide these codes???

Are you talking about a databound listbox/combobox?
 
Fabio

I understand when the user clicks the listbox you want to
look up a reference number stored with the text

In VB6, ItemData would have done this. In VB.Net, you can
do something much more powerful. You can put objects in
your list. In the example below, I've set up a structure
which has a text item (to go in the list) and an index
item. Note I've included an interface so the items can be
sorted in the listbox.

'structure to hold info to go in list
Structure ListStructure
Implements IComparable 'for sort

Dim Text As String
Dim Index As Integer

Sub New(ByVal sText As String, ByVal sIndex As
Integer)
Text = sText
Index = sIndex
End Sub

Overrides Function ToString() As String
Return Text
End Function

'this bit handles sort
Public Function CompareTo(ByVal obj As Object) As
Integer Implements System.IComparable.CompareTo
Return StrComp(Text, DirectCast(obj.text,
ListStructure).Text)
End Function

End Structure

'this is how you add items
str = New ListStructure(xText, xIndex) : cmbList.Items.Add
(str)
'..end loop

'this is how you retrieve items
'get the text
Dim tText as Integer= DirectCast(cmbList.Items
(cmbList.SelectedIndex), ListStructure).Text
'get the index
Dim tIndex as Integer= DirectCast(cmbList.Items
(cmbList.SelectedIndex), ListStructure).Index


Dermot Balson
Free VBA code for user interfaces, internet connectivity,
encryption
http://www.webace.com.au/~balson/InsaneExcel/Default.html
Last updated August 2003
 
Back
Top