Component Designs Support Forums
CDI Support Forums

Forums | Login | Join | My Profile | Inbox | Address Book | My Subscription  
My Forums | Member List | Search | Contact Admin | Log Out  

Classy Listbox & Combobox

 
Logged in as: Guest
  Printable Version
All Forums >> [Consulting] >> Consulting Services >> Classy Listbox & Combobox Page: [1]
Login
Message << Older Topic   Newer Topic >>
Classy Listbox & Combobox - 4/7/2005 8:12:26 PM   
skyjo

 

Posts: 1
Joined: 4/7/2005
Status: offline
Firstly, Hello to everyone out there!

I have been using the "DataItem" class in my project and it has helped tremendously in improving my data management where storing IDs related to a record placed in a combobox or listbox is no longer a problem.

I do however have difficulty restoring the values (IDs) from the database onto a listbox.

Using the class below I have placed items in a listbox with the following code:
' i is the ID related to strValue, both retrieved from the database

while database is reading row by row
      ListBox1.Items.Add(new DataItem(i, strValue))
      next database row
end while


Public Class DataItem
    Private _id As String
    Private _value As String

    Public Sub New(ByVal id As String, ByVal value As String)
        _id = id
        _value = value
    End Sub

    Public ReadOnly Property ID() As String
        Get
            Return _id
        End Get
    End Property

    Public ReadOnly Property Value() As String
        Get
            Return _value
        End Get
    End Property

    Public Overrides Function ToString() As String
        Return Value
    End Function


The above works flawlessly, and when the user picks a listbox item, I am able to retrieve the associated ID using the following:
sValue = listbox1.Items.Item(listbox1.SelectedIndex).id


The value is then stored in a database table along with other values that are on the windows form.

What I need now is to pre-select the item on the listbox when the form loads up with that record. I need a way to relate sValue to the items in the listbox, which has been retrieved from the database record.
I have tried the following which does not work because sValue is not the index in the listbox:
listbox1.selectedindex = sValue
'or
listbox1.selecteditem = sValue


Please help me
Post #: 1
RE: Classy Listbox & Combobox - 4/8/2005 7:33:29 AM   
Maxx

 

Posts: 287
Joined: 3/22/2004
Status: offline
Try using the indexof method

_____________________________

Director of CDI Support

(in reply to skyjo)
Post #: 2
Page:   [1]
All Forums >> [Consulting] >> Consulting Services >> Classy Listbox & Combobox Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


© Copyright Component Designs, Inc. 2001-2005. All rights reserved.

0.031