I'm new to the forum, but it looks like a great place to learn, so I'm glad I discovered it.
Anyhow, I'm very new to VB.net/Vb2005. I just finished my first semester learning VB and I'm working on a few personal projects to solidify/increase what I've learned this year. Right now I'm building a simple inventory application that will keep track of individual users at my job.
The problem I'm having is in trying to populate a comboBox with items from a text file. My goal is that when the application loads, a comboBox will be populated with the names of users(located in a text file.) Upon selecting a user, the application will read some other(like users name, windows version, computer name, etc) data from another text file and populate the applications text boxes with that information.
I know how to go about building most of the application, but the problem I'm running into is how to use a text file to populate the comboBox. If I use an array or a collection for the comboBox data, then the user list will be lost each time the application closes. Also, whenver a new user is added, that data will be lost, because the collection or orray will be lost each time the application ends. Also, I don't want to use a database for the program, just a simple file.
Here is the code I have worked out so far.
Imports System.IO
Public Class MyInventoryForm
Private output As StreamWriter
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim userNames As String = "user_names.txt"
userComboBox.DataSource = userNames
End Sub ' Form Load
Private Sub NewUserAddUserButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewUserAddUserButton.Click, Button1.Click
End Sub
Private Sub saveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles saveButton.Click
Dim filename As String = ("user_data.txt")
'Create new stream to append data to the file
output = New StreamWriter(filename, True)
output.WriteLine(lastNameTextBox.Text)
output.WriteLine(firstNameTextBox.Text)
output.WriteLine(departmentTextBox.Text)
output.WriteLine(extensionTextBox.Text)
output.WriteLine(cellPhoneTextBox.Text)
output.WriteLine(supervisorExtensionTextBox.Text)
output.WriteLine(adUserNameTextBox.Text)
output.WriteLine(adPasswordTextBox.Text)
output.WriteLine(adEmailTextBox.Text)
output.WriteLine(adWebAccessComboBox.SelectedItem)
output.WriteLine(compNameTextBox.Text)
output.WriteLine(IpAddressTextBox.Text)
output.WriteLine(winVerTextBox.Text)
output.WriteLine(memoryTextBox.Text)
output.WriteLine(hardDiskTextBox.Text)
output.WriteLine(cpuSpeedTextBox.Text)
output.WriteLine("")
output.Close()
saveButton.Enabled = False
DisableInput()
End Sub
Private Sub DisableInput()
lastNameTextBox.Enabled = False
firstNameTextBox.Enabled = False
departmentTextBox.Enabled = False
extensionTextBox.Enabled = False
cellPhoneTextBox.Enabled = False
supervisorExtensionTextBox.Enabled = False
adUserNameTextBox.Enabled = False
adPasswordTextBox.Enabled = False
adEmailTextBox.Enabled = False
adWebAccessComboBox.Enabled = False
compNameTextBox.Enabled = False
IpAddressTextBox.Enabled = False
winVerTextBox.Enabled = False
memoryTextBox.Enabled = False
hardDiskTextBox.Enabled = False
cpuSpeedTextBox.Enabled = False
End Sub
End Class
When I try to use a text file as the data source of the comboBox, I receive this error: "ystem.ArgumentException: Complex DataBinding accepts as a data source either an IList or an IListSource." I'm assuming this is because the comboBox is expecting a collection or an array as its data. But there must be a way to use a text file to populate a comboBox, right? Otherwise, the data would always be lost?
I'm sure I'm missing something here. Any ideas would be very appreciated:)

New Topic/Question
Reply




MultiQuote




|