I wanted to learn about user controls so I decided to try to duplicate the old VB5 DriveListBox using a Combo box. The problem I am having is that all the items in the listbox are entered twice (The first 5 items are repeated a 2nd time. Here are the steps I used with VB2005 (but it also happens with VB2017). I have reduced the code down to a simple example.
I start a new project and name it "text case".
I add a new class to the project called DriveListBox. Here is the code for the new class
Next I build "test case" and drag control DriveListBox1 from the ToolBox onto Form1 of the project.
When I run the program in debug mode, DriveListBox contains 10 entries, Item 1 thru Item 5 and then Item 1 thru Item 5 again. I know the 2nd set of 5 entries are coming from the code in Form1Designer.vb.
Can anyone explain to me why this is happening and how to fix it? I would be very grateful.
I start a new project and name it "text case".
I add a new class to the project called DriveListBox. Here is the code for the new class
VB.NET:
Public Class DriveListBox
Inherits ComboBox
Public Sub New()
Items.Clear()
Sorted = False
DropDownStyle = ComboBoxStyle.DropDownList
For i As Integer = 1 To 5
Items.Add("Item " & i.ToString)
Next
SelectedIndex = 1
SelectedText = Items(1)
End Sub
End Class
Next I build "test case" and drag control DriveListBox1 from the ToolBox onto Form1 of the project.
When I run the program in debug mode, DriveListBox contains 10 entries, Item 1 thru Item 5 and then Item 1 thru Item 5 again. I know the 2nd set of 5 entries are coming from the code in Form1Designer.vb.
Can anyone explain to me why this is happening and how to fix it? I would be very grateful.
Last edited by a moderator: