Solved

Display items created in listbox on mainform textbox

Posted on 2013-01-22
3
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 86

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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