Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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<string> 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)
            {
                
                    dataGridView1.Rows.Clear();
                
                dataGridView1.Refresh();
                DataTable studentbind = ibl4.studentbindformale(sdt);
                int rowcount = studentbind.Rows.Count;
                List<string> 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<string> 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 "
Cannot clear the list
". i want to display the appropriate value for appropriate radiobutton click event.
please find solve my problem.
Thank you
Posted 7-Nov-12 21:56pm

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 397
1 OriginalGriff 350
2 thatraja 205
3 Emre Ataseven 165
4 Shai Vashdi 150
0 Sergey Alexandrovich Kryukov 8,894
1 OriginalGriff 5,200
2 Peter Leow 3,955
3 Maciej Los 3,535
4 Abhinav S 3,208


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid