Hi,
I have combobox and 2 buttons (Save and open button).
When I click Save button I want combobox.text save in .txt file, and when I click Open button I want text from .txt file copy to combobox.
Thanks for help!!!
Printable View
Hi,
I have combobox and 2 buttons (Save and open button).
When I click Save button I want combobox.text save in .txt file, and when I click Open button I want text from .txt file copy to combobox.
Thanks for help!!!
vb Code:
'save items Dim items(ComboBox1.Items.Count - 1) As String ComboBox1.Items.CopyTo(items, 0) IO.File.WriteAllLines("yourtextfile.txt", items)
vb Code:
'reload items ComboBox1.Items.AddRange(IO.File.ReadAllLines("yourtextfile.txt"))
not working...
I want to make these buttons using SaveFileDialog and OpenFileDialog...
vb Code:
dim ofd as new openfiledialog if ofd.showdialog = dialogresult.ok then 'reload items ComboBox1.Items.AddRange(IO.File.ReadAllLines(ofd.filename)) end if
savefiledialog works the same way
vb Code:
Dim ofd As New OpenFileDialog ofd.InitialDirectory = "C:\" ofd.FileName = "" ofd.Filter = "Text Files (*.txt)|*.txt" ofd.Title = "Open" ofd.ShowDialog() If ofd.showdialog = DialogResult.OK Then ComboBox1.Items.AddRange(IO.File.ReadAllLines(ofd.filename)) End If
not working :S
first remove the first ofd.ShowDialog()
when I click open nothing is happening...
can you post the full open button code?
vb Code:
Dim ofd As New OpenFileDialog ofd.InitialDirectory = "C:\" ofd.FileName = "" ofd.Filter = "Text Files (*.txt)|*.txt" ofd.Title = "Open" ofd.ShowDialog() If ofd.showdialog = DialogResult.OK Then ComboBox1.Items.AddRange(IO.File.ReadAllLines(ofd.filename)) End If
i meant to include:
vb Code:
private sub button1_click 'etc
also. as i said earlier, in your code in post #10, remove line 6
vb Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim ofd As New OpenFileDialog ofd.InitialDirectory = "C:\" ofd.FileName = "" ofd.Filter = "Text Files (*.txt)|*.txt" ofd.Title = "Open" If ofd.showdialog = DialogResult.OK Then ComboBox1.Items.AddRange(IO.File.ReadAllLines(ofd.filename)) End If End Sub End Class
does the openfiledialog appear?
have you tried opening the combobox dropdown?
Yes, ofd appear. I tried opening combobox dropdown but nothing there...
ok open the same text file in notepad + tell me what it contains
You helped me now...it contains nothing... :D
Now text is copied in dropdown...can I copy text in combobox but not in dropdown(if you know what I mean) .
And second problem is Save Button:
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim SD As New SaveFileDialog() SD.InitialDirectory = "C:\" SD.Filter = "Text Files (*.txt)|*.txt" SD.Title = "Save Page To Bookmark" SD.FileName = "" SD.ShowDialog() Dim items(ComboBox1.Text.Count - 1) As String ComboBox1.Items.CopyTo(items, 0) IO.File.WriteAllLines(SD.FileName, items) End Sub
It gives me error here:
vb Code:
IO.File.WriteAllLines(SD.FileName, items)
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim SD As New SaveFileDialog() SD.InitialDirectory = "C:\" SD.Filter = "Text Files (*.txt)|*.txt" SD.Title = "Save Page To Bookmark" SD.FileName = "" if SD.ShowDialog = DialogResult.OK Then io.file.WriteAlltext(SD.FileName, combobox1.text) end if End Sub
You really helped me...
Thank you!! :)