0
votes

i want to add a row in datagridview as soon as i check the checkbox. if i check another checkbox then another row should be added.if i uncheck any checkbox then the related row should be removed from the datagrid leaving the checked 1s in datagrid . pls help ive tried this by inserting own columns and rows but i want rows from the database . pls help and thank you in advance, regards . i hav a code something like this :

SqlConnection con7 = new SqlConnection("Data Source = .;Initial Catalog = SAHS;integrated security = true");
            con7.Open();
            SqlCommand cmd3 = new SqlCommand("select Status from vw_stdtfeedetail where Std=" + comboBox2.SelectedItem + " and Div ='" + comboBox3.SelectedItem + "' and name='" + comboBox4.SelectedItem + "' and mnthname ='August'", con7);
            SqlDataReader dr = cmd3.ExecuteReader();
            BindingSource bs = new BindingSource();
            bs.DataSource = dr;
            dataGridView3.DataSource = bs;
            this.monthFeeTableAdapter.Fill(this.sAHSDataSet4.MonthFee);
            int testrow = dataGridView3.Rows.Count;
            for (int i = 0; i < testrow; i++)
            {
                if (dataGridView3.Rows[i].Cells[0].Value == DBNull.Value)
                {
                    SqlConnection con4 = new SqlConnection("Data Source = .;Initial Catalog = SAHS;integrated security = true");
                    con4.Open();
                    SqlCommand cmd4 = new SqlCommand("Select mnthname , Description, Amount from monthfee where mnthname='August'", con4);
                    SqlDataReader dr1 = cmd4.ExecuteReader();
                    BindingSource bs1 = new BindingSource();
                    bs1.DataSource = dr1;
                    dataGridView1.DataSource = bs1;
                    this.monthFeeTableAdapter.Fill(this.sAHSDataSet4.MonthFee);
                    con4.Close();
                    break;
                    /*SqlDataReader dr1 = cmd4.ExecuteReader();
                    BindingSource bs3 = new BindingSource();
                    bs3.DataSource = dr1;
                    dataGridView1.DataSource = bs3;
                    this.monthFeeTableAdapter.Fill(this.sAHSDataSet4.MonthFee);*/
                }
1
What checkbox are you referring to? You haven't described what you are trying to do very well. - David Hall
You want to add a new row of data or you want to add a new row which is blank at first and editable to add new text in the row of dataviewgrid? - Nagaraj Tantri
when i select a checkbox,datagridview should be filled with a row from database..we can use where clause , for eg: i checked the month june n from database it should call the row where month = "June" and show it in datagrid and if i uncheck it again then it should be removed.. sorry for confusing , hope now im clear .. @NagarajTantri i dnt want to edit them .. - HMcompfreak

1 Answers

0
votes

Set AutoPostback=True for the checkboxes. Then in the checked change event for the checkboxes, reload the gridview with new where clause.