Error in datagridview

Nov 8 2012 4:11 AM
Hi friends The below code is for binding datasource to datagridview for three radiobutton checked event.
 private void button6_Click(object sender, EventArgs e)
{
sdt.ACADAMICYEAR = textBox4.Text;
 sdt.CLASSID = Convert.ToInt32(comboBox1.SelectedValue.ToString());
 if (radioButton1.Checked == true)
{
DataTable studentbind = ibl4.studentbindforfemale(sdt);
 int rowcount = studentbind.Rows.Count;
List no = ibl4.setnoofint(rowcount);
 int registerno = ibl4.getregiter(sdt);
dataGridView1.DataSource = studentbind;
 DataGridViewTextBoxColumn fourthcolumn = new DataGridViewTextBoxColumn(); fourthcolumn.HeaderText = "RegNo";
 fourthcolumn.Name = "RegNo";
dataGridView1.Columns.Add(fourthcolumn);
 for (int i = 0; i < rowcount; i++)
 {
dataGridView1.Rows[i].Cells[3].Value = registerno;
}
DataGridViewComboBoxColumn fifthcolumn=new DataGridViewComboBoxColumn(); fifthcolumn.HeaderText="RegNo";
 fifthcolumn.Name="RegNo";
dataGridView1.Columns.Add(fifthcolumn);
 for (int i = 0; i < rowcount; i++)
 {
 fifthcolumn.DataSource = no;
 }
}
 if (radioButton2.Checked == true)
{ dataGridView
1.Rows.Clear(); dataGridView1.Refresh();
 DataTable studentbind = ibl4.studentbindformale(sdt);
int rowcount = studentbind.Rows.Count;
 List no = ibl4.setnoofint(rowcount);
 int registerno = ibl4.getregiter(sdt);
 dataGridView1.DataSource = studentbind;
 DataGridViewTextBoxColumn fourthcolumn = new DataGridViewTextBoxColumn(); fourthcolumn.HeaderText = "RegNo";
 fourthcolumn.Name = "RegNo";
dataGridView1.Columns.Add(fourthcolumn);
 for (int i = 0; i < rowcount; i++)
 {
 dataGridView1.Rows[i].Cells[3].Value = registerno;
 }
 DataGridViewComboBoxColumn fifthcolumn = new DataGridViewComboBoxColumn(); fifthcolumn.HeaderText = "RegNo";
 fifthcolumn.Name = "RegNo";
 dataGridView1.Columns.Add(fifthcolumn);
for (int i = 0; i < rowcount; i++)
{
 fifthcolumn.DataSource = no;
}
}
 if (radioButton3.Checked == true)
 {
 dataGridView1.Rows.Clear();
 dataGridView1.Refresh();
 DataTable studentbind = ibl4.studentbindforgeneral(sdt);
 int rowcount = studentbind.Rows.Count;
 List no = ibl4.setnoofint(rowcount);
 int registerno = ibl4.getregiter(sdt);
 dataGridView1.DataSource = studentbind;
 DataGridViewTextBoxColumn fourthcolumn = new DataGridViewTextBoxColumn(); fourthcolumn.HeaderText = "RegNo";
 fourthcolumn.Name = "RegNo";
 dataGridView1.Columns.Add(fourthcolumn);
 for (int i = 0; i < rowcount; i++)
 {
 dataGridView1.Rows[i].Cells[3].Value = registerno;
 }
 DataGridViewComboBoxColumn fifthcolumn = new DataGridViewComboBoxColumn(); fifthcolumn.HeaderText = "RegNo";
 fifthcolumn.Name = "RegNo";
dataGridView1.Columns.Add(fifthcolumn);
 for (int i = 0; i < rowcount; i++)
{
fifthcolumn.DataSource = no;
}
 }
 }

 when i click signle radiobutton(any of three) for button event, it gives a expected result.but if i click the second radiobutton and it does add the result to already datagridvalue. for clearing datagridview i use datagridview.rows.clear(). but it raise an error as " Collapse | Copy Code Cannot clear the list ". i want to display the appropriate value for appropriate radiobutton click event. please find solve my problem. Thank you

Answers (1)