|
-
Jan 3rd, 2010, 10:41 AM
#1
Thread Starter
Member
[RESOLVED] Save to text and open text
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!!!
-
Jan 3rd, 2010, 10:52 AM
#2
Re: Save to text and open text
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"))
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 11:03 AM
#3
Thread Starter
Member
Re: Save to text and open text
not working...
I want to make these buttons using SaveFileDialog and OpenFileDialog...
-
Jan 3rd, 2010, 11:06 AM
#4
Re: Save to text and open text
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 11:15 AM
#5
Thread Starter
Member
Re: Save to text and open text
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
-
Jan 3rd, 2010, 11:17 AM
#6
Re: Save to text and open text
 Originally Posted by yacky
not working :S
not working, doesn't tell me what the problem is. in what way isn't it working?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 11:19 AM
#7
Re: Save to text and open text
first remove the first ofd.ShowDialog()
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 11:21 AM
#8
Thread Starter
Member
Re: Save to text and open text
when I click open nothing is happening...
-
Jan 3rd, 2010, 11:23 AM
#9
Re: Save to text and open text
can you post the full open button code?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 11:27 AM
#10
Thread Starter
Member
Re: Save to text and open text
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
-
Jan 3rd, 2010, 11:30 AM
#11
Re: Save to text and open text
i meant to include:
vb Code:
private sub button1_click 'etc
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 11:31 AM
#12
Re: Save to text and open text
also. as i said earlier, in your code in post #10, remove line 6
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 11:34 AM
#13
Thread Starter
Member
Re: Save to text and open text
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
-
Jan 3rd, 2010, 11:36 AM
#14
Re: Save to text and open text
does the openfiledialog appear?
have you tried opening the combobox dropdown?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 11:39 AM
#15
Thread Starter
Member
Re: Save to text and open text
Yes, ofd appear. I tried opening combobox dropdown but nothing there...
-
Jan 3rd, 2010, 11:41 AM
#16
Re: Save to text and open text
ok open the same text file in notepad + tell me what it contains
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 11:47 AM
#17
Thread Starter
Member
Re: Save to text and open text
You helped me now...it contains nothing... 
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)
-
Jan 3rd, 2010, 11:51 AM
#18
Re: Save to text and open text
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 12:00 PM
#19
Thread Starter
Member
Re: Save to text and open text
You really helped me...
Thank you!!
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
|