Solved

Display items created in listbox on mainform textbox

Posted on 2013-01-22
3
253 Views
Last Modified: 2013-01-28
Hi.

I have created a mainform that will contain a combobox with 3 options, radiobuttons, textbox and listbox.  When the user selects Listbox, a new form is opened and will allow the user to add items to a listbox.  Now, I want to save those items to an array, such that when the user clicks the close button on that subform, a textbox must appear on the mainform, listing all the items, (seperated by a comma), in that textbox.

Any idea how to store my listbox items in an array and pass it back to my mainform to be listed in a textbox?
0
Comment
Question by:Jasmin01
3 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38804940
Given that you will display the items in a text box, you do not need an array. Just append the items together separated by comma and use a public variable on main form or directly access the textbox on mainform to post this string.
0
 

Author Comment

by:Jasmin01
ID: 38804959
This is what I have so far:

Behind the combobox with "List" selected :
ElseIf cboSelType.SelectedIndex = 3 Then
            Dim formListbox = New frmListbox
            Me.Visible = False
            formListbox.Show()

Open in new window

Behind the Save button of the Listbox form:
 Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
        IO.File.WriteAllLines("listbox.txt", lstAddItems.Items.Cast(Of String).ToArray)
    End Sub

Open in new window

What would I need to do?
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 38805449
Just do:
ElseIf cboSelType.SelectedIndex = 3 Then
            Dim frmLB As New frmListbox
            If frmLB.ShowDialog() = DialogResult.Ok Then ' <-- code STOPS here until "frmLB" is dismissed
                Dim values() As String = frmLB.lstAddItems.Items.Cast(Of String).ToArray
                ' ... we are in the main form still, do something with "values" ...
                TextBox1.Text = String.Join(",", values)
            End If

Open in new window


In frmListbox, you dismiss the dialog by setting DialogResult:
Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
    Me.DialogResult = DialogResult.Ok
End Sub

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now