My problem:
I have a DataSet
with multiple DataTables
in it.
All of these DataTables
have a DataColumn
named "Id" with a DataType
of System.Guid
.
A short example of such a table:
+--------------------+
| User |
+--------------------+
| *Id as System.Guid |
| Username as String |
| /* more columns */ |
+--------------------+
I assigned this DataTable
to a DataGridView
. The DataGridView
is configured to allow creating, editing and deletion of entries.
When a user now creates a new entry and saves it, there is an exception that the "Id" is unset.
My question:
How is it possible to automatically generate a new System.Guid
for new entries?
My current thoughts:
- Specifying some magic value in
dataSet.dataTable.Columns['Id'].DefaulValue
. (Something like the<DBNull>
) - Using something like a trigger on
dataSet.dataTable
listening for new rows. It would have to get executed before the row gets validated - Same thing like the trigger, but on the
dataGridView
.
What I've tried:
- These events of the
DataGridView
:RowsAdded
,UserAddedRow
,RowValidating
,DefaultValuesNeeded
It would be awesome if anyone would have a working solution or a hint for me!
~Chris