4

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?

2
  • Maybe it is not in the events, it is the way how you get the string value from the listbox. A little source would be nice ;) Commented Jan 8, 2010 at 14:51
  • all of the answers were helpful and informing. thanks, i'd accept them all if it would let me. Commented Jan 8, 2010 at 15:02

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.