سؤال

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.

هل كانت مفيدة؟

المحلول

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);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top