SINEtist
asked on
Checked listbox checked items to text box in VB.NET- 500pts, urgent
Hello,
I'm working on a question list for a VB.NET program.
I have a list of questions from a text file that I want to read into a checked list box. (each line of the text file will represent 1 line of the checked listbox) After the questions are added to the list box the user can then check off the questions they want to answer. they will hit a button, and then only the checked off items should be placed into a multi-line text box (again, maintaining each question on one line).
There will be a fixed maximum of 30 questions (lines of text in text file).
I'm not that hot of a programmer, so please keep that in mind when answering (sorry).
This is kind of urgent, hence the 500 points.
Thank you _very_ much!
I'm working on a question list for a VB.NET program.
I have a list of questions from a text file that I want to read into a checked list box. (each line of the text file will represent 1 line of the checked listbox) After the questions are added to the list box the user can then check off the questions they want to answer. they will hit a button, and then only the checked off items should be placed into a multi-line text box (again, maintaining each question on one line).
There will be a fixed maximum of 30 questions (lines of text in text file).
I'm not that hot of a programmer, so please keep that in mind when answering (sorry).
This is kind of urgent, hence the 500 points.
Thank you _very_ much!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
carl_tawn,
Your code looks promising, but I am getting some errors: ( i may not have something set correctly)
========================== ========== ========== ========== ========== ========== ========== ========== ========
Error1:
'EndOfStream' is not a member of 'System.IO.StreamReader'.
offending code:
While Not sr.EndOfStream
========================== ========== ========== ========== ========== ========== ========== ========== ========
there are also two other errors, which may or may not be relevant after considering the first error:
========================== ========== ========== ========== ========== ========== ========== ========== ========
Error2:
D:\VisualBasicProjects\que stion_list _test\Form 1.vb(108): 'System.IO.FileStream.Prot ected Overridable Sub Dispose(disposing As Boolean)' is not accessible in this context because it is 'Protected'.
offending code:
fs.Dispose()
========================== ========== ========== ========== ========== ========== ========== ========== ========
Error3:
D:\VisualBasicProjects\que stion_list _test\Form 1.vb(107): 'System.IO.StreamReader.Pr otected Overrides Sub Dispose(disposing As Boolean)' is not accessible in this context because it is 'Protected'.
offending code:
sr.Dispose()
========================== ========== ========== ========== ========== ========== ========== ========== ========
Any help on this would be greatly appreciated.
Thank you!
Your code looks promising, but I am getting some errors: ( i may not have something set correctly)
==========================
Error1:
'EndOfStream' is not a member of 'System.IO.StreamReader'.
offending code:
While Not sr.EndOfStream
==========================
there are also two other errors, which may or may not be relevant after considering the first error:
==========================
Error2:
D:\VisualBasicProjects\que
offending code:
fs.Dispose()
==========================
Error3:
D:\VisualBasicProjects\que
offending code:
sr.Dispose()
==========================
Any help on this would be greatly appreciated.
Thank you!
ASKER
i've been working on this....
I tried closing the stream reader and file stream instead of using Dispose() and managed to get rid of the last two errors.
new code:
sr.Close()
fs.Close()
I'm not sure if this will break anything or not. I'm still really stuck on the first part though.
I tried closing the stream reader and file stream instead of using Dispose() and managed to get rid of the last two errors.
new code:
sr.Close()
fs.Close()
I'm not sure if this will break anything or not. I'm still really stuck on the first part though.
ASKER
well, I got it working.
I found this thread and combined it with the procedure that carl_tawn wrote for the button.
https://www.experts-exchange.com/questions/20918450/save-to-textfile-and-get-values-from-textfile-to-a-listbox-vb-net.html?query=vb.net+listbox+to+textbox&clearTAFilter=true
here is the full code:
========================== ========== ========== ========== ========== ========== ========== ========== =========
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sr As StreamReader = New StreamReader("C:\questions .txt")
Dim line As String
line = sr.ReadLine()
While Not line Is Nothing
CheckedListBox1.Items.Add( line)
line = sr.ReadLine()
End While
sr.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim list As String = String.Empty
For Each s As String In CheckedListBox1.CheckedIte ms
list += s + vbCrLf
Next
TextBox1.Text = list
End Sub
End Class
========================== ========== ========== ========== ========== ========== ========== ========== =========
Thank you to all!!
I found this thread and combined it with the procedure that carl_tawn wrote for the button.
https://www.experts-exchange.com/questions/20918450/save-to-textfile-and-get-values-from-textfile-to-a-listbox-vb-net.html?query=vb.net+listbox+to+textbox&clearTAFilter=true
here is the full code:
==========================
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sr As StreamReader = New StreamReader("C:\questions
Dim line As String
line = sr.ReadLine()
While Not line Is Nothing
CheckedListBox1.Items.Add(
line = sr.ReadLine()
End While
sr.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim list As String = String.Empty
For Each s As String In CheckedListBox1.CheckedIte
list += s + vbCrLf
Next
TextBox1.Text = list
End Sub
End Class
==========================
Thank you to all!!
http://www.startvbdotnet.com/controls/clb.aspx
heres how you add
http://www.startvbdotnet.com/controls/listbox.aspx
and how to make the textbox multiline
http://www.startvbdotnet.com/controls/textbox.aspx