none
Add empty row to Datagridview RRS feed

  • Question

  • Hi all

    I have a datagridview (DGV) bound to Bindingsource (BS1)

    BS1 bound to DataTable

    How is it possible to add an  empty row to DGV without adding it to DataTable) ?

    I know that is possible to add a row directly in BS1 at a specific index (without add it to Datatable) but how this empty row can have the same columns of other rows ?

    Thanks for help

    Sunday, September 16, 2018 6:55 AM

Answers

  • Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.

    Sincerely, Highly skilled coding monkey.

    • Marked as answer by Claudio111 Sunday, September 16, 2018 1:49 PM
    Sunday, September 16, 2018 7:47 AM

All replies

  • One simple way to go about adding empty rows is this. First you need to add the Columns.

    //You can assign the Column types while initializing
    DataGridViewColumn d1 = new DataGridViewTextBoxColumn();
    DataGridViewColumn d2 = new DataGridViewCheckBoxColumn();
    DataGridViewColumn d3 = new DataGridViewImageColumn();
    
    //Add Header Texts to be displayed on the Columns
    d1.HeaderText = "Column 1"; 
    d2.HeaderText = "Column 2";
    d3.HeaderText = "Column 3";
    
    //Add the Columns to the DataGridView
    DataGridView1.Columns.AddRange(d1, d2, d3);
    
    //Finally add the Rows
    DataGridView1.Rows.Add(5);

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. profile for Sajeetharan at Stack Overflow, Q&A for professional and enthusiast programmers

    Sunday, September 16, 2018 7:11 AM
  • Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.

    Sincerely, Highly skilled coding monkey.

    • Marked as answer by Claudio111 Sunday, September 16, 2018 1:49 PM
    Sunday, September 16, 2018 7:47 AM