Question

I have this super simple example, where I placed a DataGridView on a form, then with the follow code:

public Form1()
{
    InitializeComponent();

    var dt = new DataTable();
    var col = dt.Columns.Add("Column 1");
    var row = dt.NewRow();
    row[0] = "test";

    var bs = new BindingSource();
    bs.DataSource = dt;

    dataGridView1.DataSource = bs;
}

no rows in the Grid. I must be missing something simple.

Was it helpful?

Solution

Try to add a newly created row to the DataTable.Rows collection:

var dt = new DataTable();
var col = dt.Columns.Add("Column 1");
var row = dt.NewRow();
row[0] = "test";
dt.Rows.Add(row);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top