You must Sign In to post a response.
  • Category: Windows

    Dynamically adding empty rows to DataGridView

    Dynamically adding empty rows to DataGridView in C# Windows application
  • #265893
    DataRow dr;
    DataSet ds; // this is bound to DataGridView

    // some logic setting up dataset and tables within

    dr = ds.Tables[0].NewRow(); // Table[0] of ds is the data I want to display
    dr["Column1"] = "Finally";
    dr["Column2"] = "Got";
    dr["Column3"] = "this";
    dr["Column4"] = "Working";

    // add row to dataset now
    ds.Tables[0].Rows.Add(dr);

    Regards,
    M.Venkatesan.

    For Interview Question and Answers:
    http://dotnet-interview-qa.blogspot.com

    http://venkatdotnetexperiments.wordpress.com

  • #293463
    We can also add empty rows in datagridview
    using this code....

    da.Fill(ds, <sourceTable>);
    for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
    {
    string columnName= ds.Tables[0].Columns[i].ColumnName;
    gridView.Columns.Add(columnName,columnName.ToUpper());
    }
    gridView.Rows.Add(10);


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.