tags:

views:

433

answers:

2

I have a pretty simple form with a listbox, a text box, and two buttons.

The list box items are populated from a sql database table. The user may chose to select one or multiple items from the listbox.

The text box is used to write more details about the items in the listbox. One button can then be clicked to update another database table with these details.

I want to make it where if any items are selected from the listbox, those contents are automatically copied into the text box field on the fly as they are selected. Is this possible?

I've been able to make this happen on the button click event - just not on the fly as they are selected. I want it to occur before the additional details are being sent to the database

I've also tried using several different listbox events, but have been unable to obtain the results I am looking for.

Any suggestions?

+1  A: 

Hey,

yes, the SelectedIndexChanged event fires on every selection change, and you can concatenate together the items in the listbox. But if you are talking the description that's not visible too, you need to store the description in each listboxitem tag property, and in your code retrieve the description from there.

Brian
+1  A: 

try this out you will have to handle the SelectedIndexChanged event on the listbox. here is an example with example controls.

    private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        textBox1.Text = "";
        foreach (string nextitem in listBox1.SelectedItems)
        {
            textBox1.Text += nextitem + " ";
        }
    }

im not too sure HOW you want the text to appear in the textbox so that would be up to you in the foreach loop.

Skintkingle