473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ComboBox Saving input in dropdown

Hello I want to have a combobox that saves all the input, so if I put
the word test in the combobox and submit a query I want to have test
saved so that the next time I go to that combobox I can click on the
letter T and all the inputs with the letter T comes through.

Aug 17 '06 #1
2 2654
Writing the search word(s) to the text file.

Sub WriteWords()
Dim sw As StreamWriter = New StreamWriter("list.txt", True,
System.Text.Encoding.UTF8)
sw.WriteLine(Me.cmbSearch.Text)
sw.Close()
End Sub

Loading the combobox entries from the text file.
Sub LoadWords()
Dim sr As StreamReader = New StreamReader("list.txt")
Dim line As String
Do Until (line Is Nothing)
line = sr.ReadLine()
Me.cmbSearch.Items.Add(line)
Loop
sr.Close()
End Sub

Usage:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
LoadWords()
End Sub

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSearch.Click
'==>Searching code here
WriteWords()
Me.cmbSearch.Items.Clear()
LoadWords()
End Sub

tr************@za.syspro.com wrote:
Hello I want to have a combobox that saves all the input, so if I put
the word test in the combobox and submit a query I want to have test
saved so that the next time I go to that combobox I can click on the
letter T and all the inputs with the letter T comes through.
Aug 17 '06 #2
Thank you very much for the help but I have done something with a bit
more complexity and that might be my problem.
I have actually tried to on submitting the form taken any items in the
listbox.items colloection and tried to write that to an xml and then at
form load I load the xml back into the listbox.items collection however
I have not gotten it to work as yet. I would like to try and get it
working like this but I will try your previous suggestion as well
Below is the code I am currently using but it obviously does not work,
I hope you can understand what I am trying to do here.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim xmlDoc As New XmlDocument
Dim frompathelem As XmlElement =
xmlDoc.CreateElement("FromPath")
Dim topathelem As XmlElement = xmlDoc.CreateElement("ToPath")
xmlDoc.Load(Application.StartupPath & "\PathEntries.xml")

Try
Dim node As XmlNode
node = xmlDoc.DocumentElement.AppendChild(frompathelem)
Dim txtfrompathxml As XmlText
node = xmlDoc.SelectSingleNode("//FromPath")
txtfrompathxml = xmlDoc.DocumentElement.AppendChild(node)
For Each myobj As Object In TxtFromPath.Items
Dim frompathcollection As XmlText =
xmlDoc.CreateTextNode(myobj)
frompathcollection =
xmlDoc.DocumentElement.AppendChild(node)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try

Try
Dim node As XmlNode
node = xmlDoc.DocumentElement.AppendChild(topathelem)
Dim txttopathxml As XmlText
node = xmlDoc.SelectSingleNode("//ToPath")
txttopathxml = xmlDoc.DocumentElement.AppendChild(node)
For Each myobj As Object In TxtToPath.Items
Dim topathcollection As XmlText =
xmlDoc.CreateTextNode(myobj)
topathcollection =
xmlDoc.DocumentElement.AppendChild(node)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try

xmlDoc.Save(Application.StartupPath & "\PathEntries.xml")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If IO.File.Exists(Application.StartupPath & "\PathEntries.xml")
= True Then
Dim xmlsaveddoc As New XmlDocument
Dim node As XmlNode
xmlsaveddoc.Load(Application.StartupPath &
"\PathEntries.xml")
Try
For Each node In xmlsaveddoc.SelectNodes("//FromPath")
txtFromPath.Items.Add(node.InnerText)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try
For Each node In xmlsaveddoc.SelectNodes("//ToPath")
txtToPath.Items.Add(node.InnerText)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
ElseIf IO.File.Exists(Application.StartupPath &
"\PathEntries.xml") = False Then
Dim xmldoc As New XmlDocument
xmldoc.LoadXml("<Root></Root>")
xmldoc.Save(Application.StartupPath & "\PathEntries.xml")
End If
End Sub

Aug 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jean | last post by:
hi: i am developing a custom combobox for my company's needs that is made up of a textbox, listbox, button. i am using c#. everything is fine except for one issue. in a normal combobox,...
7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
7
by: NCrum | last post by:
I want to set the Default value of a Combobox for any changeable record and have got this working but it is totaly unsatisfactory see the code below I loop through the items in the Combo looking...
0
by: Mike | last post by:
Hi all! I have an OwnerDrawVariable ComboBox in .net. In the ComboBox DropDown event I display another control - works well. In the control's Leave event I remove the control - works well. So...
4
by: Kalvin | last post by:
I have seen this question raised, but I cannot find an answer. I have an MDI app, when I load an child form with a combobox being bound in the load event, it won't allow me to set selectedindex =...
3
by: **Developer** | last post by:
I want to have a ComboBox that is loaded programmically not except keyboard inputs. I tried in KeyDown not calling MyBase.OnKeyDown(e) and also tried setting e.Handled = True but neither appear...
0
by: | last post by:
Hi All. I have a problem with combobox, what I want is when combobox gets focus I need it to show the dropdown list t.This is fine if the user selects the combobox via keystrokes but when the...
5
by: Gil | last post by:
Is there a way to tell if a combbox is in dropdown mode. I tried and if statement combobox.dropdown = true but i get an error. dropwndown function doesnt store if its true or false what i am...
1
by: amber | last post by:
I'm having an issue with a combobox that is making no sense to me at all. I have a form with several comboboxes/textboxes. The values in these boxes are based on a datarowview, which is based on...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.