Tharake Gunatilake

Tharake Gunatilake

  • NA
  • 53
  • 73.2k

add multiple rows to a data grid view

Feb 12 2013 6:11 AM
I'm new to c#.
I want to add values of text boxes to a data grid view..I used this coding in the button click event.

    DataTable table = new DataTable();           

            table.Columns.Add("STU_ID", typeof(string));
            table.Columns.Add("NAME", typeof(string));
            table.Columns.Add("ADDR", typeof(string));
            table.Columns.Add("PHONE", typeof(string));
            table.Columns.Add("EMAIL", typeof(string));
            table.Columns.Add("BIRTHDATE", typeof(DateTime));
            table.Columns.Add("SEX", typeof(string));

            table.Rows.Add(textBox1.Text,textBox2.Text,textBox3.Text,textBox4.Text,textBox5.Text,dateTimePicker1.Value.ToString(),comboBox1.Text);

            dataGridView1.DataSource = table;      

It only add one row.When i try to add aothe set of values the grid view replaces the previous row.I need to keep the previous row and add the new row.
I d be very much thankful if someone can help me..

Answers (4)