|
-
Jul 28th, 2011, 03:53 AM
#1
Thread Starter
Addicted Member
[RESOLVED] combo box remember user input
hi to all please help me on this one, here is my problem i have a combo box without a list of item now i want to do is when a user input a number or text in combo box the text value of the combo box will be saved and when the user input the same number the combo box will not save the same text value. and when the user logout and login back again i want to load the list of item that he or she inputted earlier in the combo box. please help can this be possible?
Last edited by acidsnake; Jul 28th, 2011 at 03:57 AM.
-
Jul 28th, 2011, 08:43 AM
#2
Re: combo box remember user input
Try the following, requires a button and a combobox. It will save the ComboBox items list to a text file and load it on startup. Validation for adding items to the ComboBox is the must be numeric and not in the current Items list.
Form code
Code:
Private MyComboBoxFile As String = _
IO.Path.Combine(Application.StartupPath, "SavedItems.txt")
Private Sub Demo_FormClosing( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles Me.FormClosing
ComboBox1.Items.SaveToFile(MyComboBoxFile)
End Sub
Private Sub Demo_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If IO.File.Exists(MyComboBoxFile) Then
ComboBox1.Items.LoadFromFile(MyComboBoxFile)
End If
End Sub
Private Sub AddItem_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If Not String.IsNullOrEmpty(ComboBox1.Text) Then
If Integer.TryParse(ComboBox1.Text, Nothing) Then
Dim pos = ComboBox1.Items.IndexOf(ComboBox1.Text)
If pos = -1 Then
ComboBox1.Items.Add(ComboBox1.Text)
End If
End If
End If
End Sub
Code module
Code:
<System.Diagnostics.DebuggerStepThrough()> _
<System.Runtime.CompilerServices.Extension()> _
Public Sub SaveToFile(ByVal sender As ComboBox.ObjectCollection, ByVal FileName As String)
System.IO.File.WriteAllLines(FileName, (From Row In sender.Cast(Of String)() Select Row).ToArray())
End Sub
<System.Diagnostics.DebuggerStepThrough()> _
<System.Runtime.CompilerServices.Extension()> _
Public Sub LoadFromFile(ByVal sender As ComboBox.ObjectCollection, ByVal FileName As String)
sender.AddRange(IO.File.ReadAllLines(FileName))
End Sub
-
Jul 28th, 2011, 10:50 PM
#3
Thread Starter
Addicted Member
Re: combo box remember user input
hi kevininstructor thanks for the code i will try this
-
Jul 28th, 2011, 11:36 PM
#4
Thread Starter
Addicted Member
Re: combo box remember user input
hi kevininstructor where i declare this
Code:
Private MyComboBoxFile As String = _
IO.Path.Combine(Application.StartupPath, "SavedItems.txt")
-
Jul 29th, 2011, 12:41 AM
#5
Thread Starter
Addicted Member
Re: combo box remember user input
hi thank you kevininstructor for this code it works like a charm man.
-
Jul 29th, 2011, 12:46 AM
#6
Re: combo box remember user input
 Originally Posted by acidsnake
hi thank you kevininstructor for this code it works like a charm man. 
Good to hear the code worked for you!
-
Jul 29th, 2011, 12:47 AM
#7
New Member
Re: [RESOLVED] combo box remember user input
Private Sub ButtonSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSave.Click
If frUpdate = False Then
IsConnected("insert into table1 values(" & _
Me.TextID.Text & ",'" & _
Me.EN.Text & "','" & _
Me.FN.Text & "','" & _
Me.LN.Text & "','" & _
Me.MN.Text & "','" & _
Me.address.Text & "','" & _
Me.sss.Text & "','" & _
Me.tin.Text & "','" & _
Me.philhealth.Text & "','" & _
Me.BD.Value & "," & _
Me.datehired.Value & "," & _
Me.status.Text & "','" & _
Me.Gender.Text & "','" & _
Me.ts.Text & "','" & _
Me.tl.Text & "','" & _
Me.typel.Text & "','" & _
Me.lb.Text & "','" & _
Me.pt.Text & "','" & _
Me.rt.Text & "','" & _
Me.tmh.Text & "','" & _
Me.mld.Text & "','" & _
Me.tms.Text & "')", True)
MsgBox("Successfully saved!", MsgBoxStyle.Information, "Information")
Call LoadID()
Else
IsConnected("Update table1 set EmployeeNumber='" & Me.EN.Text & _
"',FirstName='" & Me.FN.Text & _
"',LastName='" & Me.LN.Text & _
"',MiddleName='" & Me.MN.Text & _
"',Address='" & Me.address.Text & _
"',SSS='" & Me.sss.Text & _
"',Tin='" & Me.tin.Text & _
"',PhilHealth='" & Me.philhealth.Text & _
"',DateOfBirth='" & Me.BD.Value & _
"',DateHired='" & Me.datehired.Value & _
"',Status='" & Me.status.Text & _
"',Gender='" & Me.Gender.Text & _
"',TotalSalary='" & Me.ts.Text & _
"',TotalLoan='" & Me.tl.Text & _
"',TypeofLoan='" & Me.typel.Text & _
"',LoanBalance='" & Me.lb.Text & _
"',PaymentTerm='" & Me.pt.Text & _
"',RemainingTerm='" & Me.rt.Text & _
"',TotalMonthHired='" & Me.tmh.Text & _
"',MonthlyLoanDeduction='" & Me.mld.Text & _
"',TotalMonthlySalary='" & Me.tms.Text & "' where ID='" & Me.TextID.Text & "'", True)
MsgBox("Successfully updated!", MsgBoxStyle.Information, "Information")
End If
End Sub
-
Jul 29th, 2011, 12:49 AM
#8
New Member
Re: [RESOLVED] combo box remember user input
i'm receiving error:
number of query value and destination fields are not the same
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|