.Net C # window forms security list question

I have a fairly simple form with a list, a text box and two buttons.

List items are populated from the sql database table. The user can select one or more items from the list.

The text box is used to record more detailed information about the items in the list. You can then click one button to update another database table with this data.

I want to do this where, if any elements are selected from the list, this content is automatically copied to the text field on the fly as they are selected. Is it possible?

I was able to do this on a button click event - just not on the fly, as they are selected. I want this to happen before additional data is sent to the database

I also tried to use several different events in the list, but could not get the results I'm looking for.

Any suggestions?

+4
source share
2 answers

try this you will have to handle the SelectedIndexChanged event in the list. here is an example with examples of 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 text box so that it is up to you in the foreach loop.

+1
source

yes, the SelectedIndexChanged event fires every time you change the selection, and you can combine the items in the list. But if you are talking about a description that also does not appear, you need to save the description in each tagboxitem property, and get a description from there in your code.

+1
source

All Articles