Passing a value from listview to a textbox in another form C#

Viewed 777

I have two forms as Main form and Product form. In the Main form I have a listview which contains the details of product. I want to sent the product id in the listview to the Product form through the 'Update' button click. Can any one help me? This is the code to bind the listview in the main form. And i have a textbox1 in Product form.

        public void BindGridProduct()
    {
    try
        {
            SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-U1OP1S9\SQLEXPRESS;Initial Catalog=PaintStores;Integrated Security=True");

            SqlCommand command = con.CreateCommand();
            command.CommandText = "sp_getAllProducts";

            SqlDataAdapter da = new SqlDataAdapter(command);
            DataTable dataTable = new DataTable();
            da.Fill(dataTable);

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                DataRow drow = dataTable.Rows[i];

                // Only row that have not been deleted
                if (drow.RowState != DataRowState.Deleted)
                {
                    // Define the list items
                    ListViewItem lvi = new ListViewItem(drow["ProductId"].ToString());
                    lvi.SubItems.Add(drow["ProductName"].ToString());
                    lvi.SubItems.Add(drow["TypeName"].ToString());
                    lvi.SubItems.Add(drow["Quantity"].ToString());
                    lvi.SubItems.Add(drow["Price"].ToString());
                    lvi.SubItems.Add(drow["Stock"].ToString());


                    // Add the list items to the ListView
                    listView2.Items.Add(lvi);
                }
            }

            con.Close();
        }

        catch(Exception ex)
        {
            throw ex;
        }
    }

And this is the button in the Main form, to pass the value to other form

        private void button22_Click_1(object sender, EventArgs e)
    {
       //code

    }

Regards

1 Answers
Related