| greenhouse wrote: |
|
Just as a short aside, I though default values could also be set in the table definition.
I tried that, but nothing happened or I did not do it correctly.
| |
Yes, this can be defined in the table definition, just set Default Value property for the specified field. Something like this
Code Block
void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("c1");
dt.Columns.Add("c2");
dt.Columns[1].DefaultValue = "default value";
for (int j = 0; j < 5; j++)
{
dt.Rows.Add("aaa", "bbb");
}
bs.DataSource = dt;
this.dataGridView1.DataSource = bs;
}
BindingSource bs = new BindingSource();
private void button1_Click(object sender, EventArgs e)
{
bs.AddNew();
}
|