Abd ul rahaman Shalata
Abd ul rahaman Shalata

Reputation: 154

add new row to datagridview programmatically

I try to add new row to datagridview ,I try by using this code

DataGridViewRow row = (DataGridViewRow)dgv_OfferTerms.Rows[0].Clone();
row.Cells[0].Value = cond.Id;
row.Cells[1].Value = cond.Name;
row.Cells[2].Value = cond.Title;
row.Cells[3].Value = cond.Description;
dgv_OfferTerms.Rows.Add(row);

it didn't work so i try this

dgv_OfferTerms.Rows.Add(cond.Id,cond.Name,cond.Title,cond.Description);

didn't work how can i add new row to datagridview??

Upvotes: 3

Views: 20452

Answers (1)

davinceleecode
davinceleecode

Reputation: 807

These code may help you:

this.dataGridView1.Rows.Add("five", "six", "seven","eight");
this.dataGridView1.Rows.Insert(0, "one", "two", "three", "four");

or:

DataGridViewRow row = (DataGridViewRow)yourDataGridView.Rows[0].Clone();
row.Cells["Column2"].Value = "XYZ";
row.Cells["Column6"].Value = 50.2;
yourDataGridView.Rows.Add(row);

Reference from:
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx

Upvotes: 4

Related Questions