Domanda

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.

È stato utile?

Soluzione

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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top