hi,
I have a datagridview bound to a database-table. the dgv shows data of an item,
where the item could be everything.
when adding a new item the dgv's DataSource has 0 rows, the dgv just shows the columns (correctly).
to add data to the item, I use
Item_CellMouseDown
to add the items id
to the new row, because the id-column is not visible in dgv.
below a two versions of the method and none works correctly.
code A :
private void Item_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
int row = e.RowIndex;
DataRow dr;
if (row == SourceTable.Rows.Count) {
dr = SourceTable.NewRow();
SourceTable.Rows.Add(dr);
dr["ID"] = this.ID;
}
}
code B :
private void Item_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
int row = e.RowIndex;
object id = Item["Id",row].Value;
if (id == null || id.ToString() == string.Empty) {
Item["Id",row].Value = this.ID;
}
}
What I have tried:
code A : Item shows three rows, SourceTable has two rows
code B : Item shows one row, SourceTable has 0 rows
however it should be Item shows two rows, SourceTable has 1 row
what am I missing or what am I doing wrong here ?
thanks in advance
franz