septaug
septaug

Reputation: 61

select item from listbox and pass it as query to other form

I have a winforms app in C# in with a user is prompted to select from a range of items, the items are displayed in a listview with the checkboxes set to true. After the user selects one item i want the description and a value from an SQL database to be displayed in another form, in 2 textboxes. Is there a way to accomplish this? I think it would be something like:

  private void button1_Click(object sender, EventArgs e)
    {
        If(listView1.SelectedItems = ??); 
        {
            "select[descri] + '  ' + [compo] from vidros" 
             pass it to form "build" in textbox "desc2"           
            "select valu from vidros" 
             pass it to form "build" in textbox "tt"
             this.close();
        }
        else
        {
            MessageBox.Show("Please select an item!", "Warning!");
        }
    }

Upvotes: 0

Views: 874

Answers (1)

Mong Zhu
Mong Zhu

Reputation: 23732

it is possible. And all the answers are here on StackOverflow:

After the user selects one item

Get single listView SelectedItem

"select[descri] + ' ' + [compo] from vidros"

How to retrieve data from a SQL Server database in C#?

pass it to form "build" in textbox "desc2"

Send values from one form to another form

I wish you success constructing all this information into working code :)

Upvotes: 1

Related Questions