|
Once data is bound
to the DataGridView control, the behavior of the control becomes very
hard to influence and I saw only one way out, and that is to implement
data binding by overriding the control's DataSource property and simply
not bind data to the base control itself.
I ran into problems when I wanted to use the following code in unbound mode:
private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
MyItem item1 = row.DataBoundItem as MyItem;
//trying to do something with item1 but item1 is null at this point
}
Could you tell me
how can I assign DataGridViewRow.DataBoundItem property for newly
create rows if I create rows using code like this? :
internal class MyRow : DataGridViewRow
{
...
}
MyRow row_temp = new MyRow();
row_temp.CreateCells(dataGridView1, "val1", "val2");
|