M
Michael Hulthin
Hello, not even sure if this is the right forum for this question but here
goes..
I'm writing a NET Data Provider for our DBMS and got everything working
except one thing. Populating a DataGrid..
All other parts of the Data Provider framework are all interface-based and
therefore rather easy to implement/override as needed, but the DataTable
isn't!
So when my TTDataTable (derived from DataTable) gets notified over TCP/IP
that a cell has changed it's value and I update the DataTable using
something like:
Rows[updateRow.RowId][cell.Ordinal] = cell.Value == null ? DBNull.Value :
cell.Value;
Sooner or later the application will throw an exception somwhere in
System.Windows.Forms.dll whith no callstack at all, very ennoying..
This happens I _think_ is because the DataTable implementation does not do
something like this when firing the event:
<someevent>Handler eventTarget = <someevent>;
if ( eventTarget != null )
{
if ( eventTarget.Target is ISynchronizeInvoke )
{
ISynchronizeInvoke target = eventTarget.Target as
ISynchronizeInvoke;
target.BeginInvoke( eventTarget, new object[]{ this<,more params
if needed> } );
}
else
{
eventTarget( this, e );
}
One solution would be to throw the event myself in the OnRowChanged method,
but unfortunatly the onRowChangedDelegate (and also the rest of the event)
seems to be private, so...
Another solution would be that I have totally missunderstood how to properly
deriving from a DataTable and populating/updating it from another thread and
if so, I really hope someone here can show me how.
Or *gasp* could it be a bug/bad coding/feature from MS? o.O
BTW when not adding the TTDataTable to a grid but instead simply sinking the
events and tracing the events using Debug.WriteLine or to a console, it
works, thats why I think it's a "updating a form from the wrong
thread"-bug..
TIA/
Michael Hulthin
goes..
I'm writing a NET Data Provider for our DBMS and got everything working
except one thing. Populating a DataGrid..
All other parts of the Data Provider framework are all interface-based and
therefore rather easy to implement/override as needed, but the DataTable
isn't!
So when my TTDataTable (derived from DataTable) gets notified over TCP/IP
that a cell has changed it's value and I update the DataTable using
something like:
Rows[updateRow.RowId][cell.Ordinal] = cell.Value == null ? DBNull.Value :
cell.Value;
Sooner or later the application will throw an exception somwhere in
System.Windows.Forms.dll whith no callstack at all, very ennoying..
This happens I _think_ is because the DataTable implementation does not do
something like this when firing the event:
<someevent>Handler eventTarget = <someevent>;
if ( eventTarget != null )
{
if ( eventTarget.Target is ISynchronizeInvoke )
{
ISynchronizeInvoke target = eventTarget.Target as
ISynchronizeInvoke;
target.BeginInvoke( eventTarget, new object[]{ this<,more params
if needed> } );
}
else
{
eventTarget( this, e );
}
One solution would be to throw the event myself in the OnRowChanged method,
but unfortunatly the onRowChangedDelegate (and also the rest of the event)
seems to be private, so...
Another solution would be that I have totally missunderstood how to properly
deriving from a DataTable and populating/updating it from another thread and
if so, I really hope someone here can show me how.
Or *gasp* could it be a bug/bad coding/feature from MS? o.O
BTW when not adding the TTDataTable to a grid but instead simply sinking the
events and tracing the events using Debug.WriteLine or to a console, it
works, thats why I think it's a "updating a form from the wrong
thread"-bug..
TIA/
Michael Hulthin