Two Values in an item of a combobox

  • Thread starter Thread starter Yavuz Bogazci
  • Start date Start date
Y

Yavuz Bogazci

Hi,

i have a question: how can i add items to my comboboxes
with more informations. For Example i want to show the
names of my customers an behind the names i want to store
id's or phonenumbers or something else. i don't want to
have a database!

thanks
yavuz
 
use displayMember and valueMember properties for the bound data

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
 
I have no bound data. i do not use a db !

-----Original Message-----
use displayMember and valueMember properties for the bound data

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.





.
 
Yavuz Bogazci said:
i have a question: how can i add items to my comboboxes
with more informations. For Example i want to show the
names of my customers an behind the names i want to store
id's or phonenumbers or something else. i don't want to
have a database!

You can add any type of object to a combobox. The ToString function of the
object returns what has to be displayed in the combobox.

Taken from a previous post:


class MyComboitem
public readonly ID as integer
public readonly Text as string
public sub new(byval ID as integer,byval Text as string)
me.id=id
me.text=text
end sub
public overrides Function ToString as string
return Text
end function
end class

'code adding items:
dim item as mycomboitem
item = new mycomboitem(theid, thetext)
combobox1.items.add(item)

'to retrieve the id from an item:
dim item as mycomboitem
item = directcast(combobox1.items(0), mycomboitem)
msgbox(item.text)
 
Private Structure vpair

dim text As String

dim value As Int32

End Structure

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim ivp As New vpair

ivp.text = "Hello"

ivp.value = 60

ComboBox1.Items.Add(ivp)

MessageBox.Show(ComboBox1.Items(2).text)

MessageBox.Show(ComboBox1.Items(2).value)

End Sub


--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
 
actually it needs 2 be a class

Private Class vpair

Public text As String

Public value As Int32

Public Overrides Function toString() As String

Return text

End Function

End Class


--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
 
great! thank you!

yavuz

-----Original Message-----
actually it needs 2 be a class

Private Class vpair

Public text As String

Public value As Int32

Public Overrides Function toString() As String

Return text

End Function

End Class


--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.


"One Handed Man" <terry_burnsREMOVE%FOR%NO%
(e-mail address removed)> wrote in
 
Back
Top