Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table with the fields like (Sno, Name, Cost, No_Of_Items).
when I want to bind this table into DataGridview with checkbox. In the bottom I have 1 add button and Textbox.....
I will checked some fields in gridview and click on add button, now I want total amount of selected items cost will appear in textbox....
Posted

C#
foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (row.Cells[1].Value != null && (bool)row.Cells[1].FormattedValue)
                {
                        DialogResult dlgRes;
                        string teststr = "Are you want to delete";
                        dlgRes = MessageBox.Show(teststr, "Confirm Document Close", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (dlgRes == DialogResult.Yes)
                        {
                            
                            int idtoselect = (int)row.Cells[0].Value;
                            String str1 = idtoselect.ToString();
                            string constr = "DELETE FROM Member Where ID_Member =" + str1 + "";
                            SqlCommand cmd = new SqlCommand(constr, conn);
                            cmd.ExecuteNonQuery();
                            ds.Tables["Member"].Clear();
                            da.Fill(ds, "Member");
                            dataGridView1.DataSource = ds.Tables["Member"];
                        }
                        else
                        {
                            ds.Tables["Member"].Clear();
                            da.Fill(ds, "Member");
                            dataGridView1.DataSource = ds.Tables["Member"];
                        }
                    }
               }


this's my code to delete record that choose by checkbox and checkbox in datagridview Row cell 1

and id is datagridview Row cell 0

Hope you bring my code to apply for your question
 
Share this answer
 
v2
Thanks for your help aniketyadav7 and pongpanut.... I got solution ....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900