user2063479
user2063479

Reputation: 33

how to insert data from textboxes to datagridview in C#

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

Answers (2)

Bijay Budhathoki
Bijay Budhathoki

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

spajce
spajce

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

Related Questions