Solved

Display items created in listbox on mainform textbox

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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