Solved

Display items created in listbox on mainform textbox

Posted on 2013-01-22
3
255 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

785 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