Reputation: 33
I have a task i.e i have to insert data from text boxes to datagridview and then save the datagridview data into database with multiple rows what i added from text boxes to datagridview.i tried some code but it is working for first row only i cont add more than one row.can any one help me how can i do this?.
private void btnAdd_Click(object sender, EventArgs e)
{
dgvUom.Rows[0].Cells["UomType"].Value = txtUomtyp.Text;
dgvUom.Rows[0].Cells["UOmDesc"].Value = txtUomDesc.Text;
}
Upvotes: 3
Views: 52926
Reputation: 186
I hope this will work for you which worked for me
DataTable dt = new DataTable();
dt = (DataTable)dgvUom.DataSource;
string firstColumn = txtUomtyp.Text;
string secondColumn = cbxVNo.Text;
string[] row = { firstColumn, secondColumn };
dGVInventory.Rows.Add(row);
Upvotes: 0
Reputation: 7082
private void btnAdd_Click(object sender, EventArgs e)
{
string firstColum = txtUomtyp.Text;
string secondColum = txtUomDesc.Text;
string[] row = { firstColum, secondColum };
dgvUom.Rows.Add(row);
}
Upvotes: 7