hi i have a button that enters some values from a datagridview1 to another datagridview2. Now the problem is that when i click the button it gives me the values of the datagridview1 to datagridview2 but now the problem is that if i press again the button for other values it writes it in the same row. i tried the datatable.newrow but not working :/ :S
Code:public void AddtoBill(DataGridView dgv) { DataGridViewRow row = dgv.SelectedRows[0]; string a = row.Cells[0].Value.ToString(); string b = row.Cells[1].Value.ToString(); DataTable dt2 = new DataTable(); dt2.Columns.Add("Product"); dt2.Columns.Add("Price"); dt2.Rows.Add(a,b); dt2.NewRow(); dgvBill.DataSource = dt2; }
this is how its done ,
declare a new row.
Code:DataGridviewrow newRow=new DataGridviewRow();Code:dgvBill.DataSource = dt2; dgvBill.DataBind(); // you forgot this
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks