ent_ttu
Member
- Joined
- Jun 17, 2008
- Messages
- 14
- Programming Experience
- 1-3
I'm new to VB, and am having trouble with yet another thing... I'm using VB.net 2005 and MS access.
Problem overview: I have a list of people in a database table that I want to put into a listbox, with a pre-determined person (the current value) already highlighted. I need to do this on several separate forms, so I thought I'd create a class for the custom listbox.
The class (rpListBox) seems to be working OK; if I tell the class to add the control to a specific form (frmEdit), it appears on the form.
If I comment out the line in the class that tells it to add to the form, and add that line to the code in the form itself, nothing appears and I don't get an error message.
Here's the code for the class I wrote:
Here's the code snippet from frmEdit that doesn't work:
I don't want to hard-code the form name in the rpListBox class, because I want to use it from different forms.
I'm sure it's something simple, and I'd appreciate any help or suggestions. Thanks!
Problem overview: I have a list of people in a database table that I want to put into a listbox, with a pre-determined person (the current value) already highlighted. I need to do this on several separate forms, so I thought I'd create a class for the custom listbox.
The class (rpListBox) seems to be working OK; if I tell the class to add the control to a specific form (frmEdit), it appears on the form.
If I comment out the line in the class that tells it to add to the form, and add that line to the code in the form itself, nothing appears and I don't get an error message.
Here's the code for the class I wrote:
VB.NET:
Public Sub New(ByVal responsibleID)
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\barcode_inventory.mdb"
con.Open()
rpSQL = "select person_id from person where status = 'a' order by last_name"
da = New OleDb.OleDbDataAdapter(rpSQL, con)
da.Fill(ds, "ppl")
MaxRows = ds.Tables("ppl").Rows.Count
inc = 0
Do While inc < MaxRows
Dim resp As New responsibleParty(ds.Tables("ppl").Rows(inc).Item("person_id"))
lstRespParty.Items.Add(resp.rpLastNameFirst)
If (resp.rpId = invNo.responsibleID) Then
lstRespParty.SelectedItem = resp.rpLastNameFirst
End If
inc = inc + 1
Loop
'this line works in this class
frmEdit.Controls.Add(lstRespParty)
End Sub
Here's the code snippet from frmEdit that doesn't work:
VB.NET:
Dim lstRespParty As New rpListBox(invNo.responsibility)
'this line doesn't do anything
Me.Controls.Add(lstRespParty)
I don't want to hard-code the form name in the rpListBox class, because I want to use it from different forms.
I'm sure it's something simple, and I'd appreciate any help or suggestions. Thanks!