|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
is there a way to do thishey all,
i'm using a listbox in my win form and was wondering if i can load an item to my listbox giving it a name/value pair (like dropdownlist) because i noticed that the available properties shows a Seletected Value and Selected Item. What would the syntax look like if this is possible? thanks, rodchar Those properties are used when binding it to a datasource
In your case it's probably easier to build a small class that holds all the data that you need, add a (overridden) ToString method and add instances of that class to your listbox. The item collection is not limited to strings, you can put anything in there. The listbox will call the ToString method of the object to determine the string to display. Example: Public Class MyItem Public Name As String Public Value As Integer Public Sub New(name As String, value As Integer) Me.Name = name Me.Value = value End Sub Public Overrides Function ToString() As String Return Me.Name End Function End Class .... myListBox.Items.Add(New MyItem(name1, value1)) myListBox.Items.Add(New MyItem(name2, value3)) myListBox.Items.Add(New MyItem(name3, value3)) .... Dim item As MyItem item = CType(myListBox.SelectedItem, MyItem) /claes Show quoteHide quote "rodchar" <rodc***@discussions.microsoft.com> wrote in message news:7A159B5F-DC0E-4995-A6BF-57E095873F27@microsoft.com... > hey all, > > i'm using a listbox in my win form and was wondering if i can load an item > to my listbox giving it a name/value pair (like dropdownlist) because i > noticed that the available properties shows a Seletected Value and > Selected > Item. What would the syntax look like if this is possible? > > thanks, > rodchar And if you bind the list box to a BindingList(Of MyItem) then it will
automatically updated as you add/removed items from the list. That way you can keep your data model separate from the UI. "rodchar" <rodc***@discussions.microsoft.com> schrieb: Check out the code samples at > i'm using a listbox in my win form and was wondering if i can load an item > to my listbox giving it a name/value pair (like dropdownlist) because i > noticed that the available properties shows a Seletected Value and > Selected > Item. What would the syntax look like if this is possible? <URL:http://dotnet.mvps.org/dotnet/code/controls/#ItemData>. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> thank you for the great help.
Show quoteHide quote "rodchar" wrote: > hey all, > > i'm using a listbox in my win form and was wondering if i can load an item > to my listbox giving it a name/value pair (like dropdownlist) because i > noticed that the available properties shows a Seletected Value and Selected > Item. What would the syntax look like if this is possible? > > thanks, > rodchar
How to release a free source code?
Dynamically open forms, reports or call functions How to convert a regular VB app into a service to run on a Windows 2003 server? Database update problems. Crypto Question FileUpload to SQL Open Printers Folder String Tokenizing - Help! An idea to save learning time. Email Issue due to Antivirus (posting again) |
|||||||||||||||||||||||