Home All Groups Group Topic Archive Search About

Weird issues with DataGrid

Author
9 Mar 2006 8:18 PM
Flack
I have a DataGrid and a DataTable.  When my form loads I create the DataTable
with the appropriate columns and use it for the DataGrids.DataSource.

Later on in my app, I alter the DataTable:

dt.BeginLoadData(); 
for(int i = 0; i < _movesArrayList.Count; i++)
{
   string[] columnValues = ((string)_movesArrayList[i]).Split(COL_SEPARATOR);
   DataRow _moveRow = dt.NewRow();
   _moveRow[0] = columnValues[0];
   _moveRow[1] = columnValues[1];
   _moveRow[2] = columnValues[2];
   dt.Rows.Add(_moveRow);
}         
dt.EndLoadData();


The thing is, every once in a while my app crashes and I get the following
error:

A first chance exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
Additional information: Object reference not set to an instance of an object.

According to the stack trace it occurs at dt.EndLoadData() and in the method

System.Windows.Forms.DataGridToolTip::CreateToolTipHandle()

I can't reliably reproduce it.  Has anyone seen anyhting like this before?

Thanks.

Following is the stack trace: system.windows.forms.dll!System.Windows.Forms.DataGridToolTip::CreateToolTipHandle() + 0x160 bytes   
system.windows.forms.dll!System.Windows.Forms.DataGrid::ResetToolTip() +
0x44 bytes   
system.windows.forms.dll!System.Windows.Forms.DataGrid::OnLayout(System.Windows.Forms.LayoutEventArgs
levent = {System.Windows.Forms.LayoutEventArgs}) + 0xa7 bytes   
system.windows.forms.dll!System.Windows.Forms.Control::PerformLayout(System.Windows.Forms.Control
affectedControl = null, String* affectedProperty = null) + 0x7b bytes   
system.windows.forms.dll!System.Windows.Forms.Control::PerformLayout() +
0x13 bytes   
system.windows.forms.dll!System.Windows.Forms.DataGrid::ResetUIState() +
0x34 bytes   
system.windows.forms.dll!System.Windows.Forms.DataGrid::SetDataGridRows(System.Windows.Forms.DataGridRow[]
newRows = null, __int32 newRowsLength = 212) + 0x7e bytes    system.windows.forms.dll!System.Windows.Forms.DataGrid::RecreateDataGridRows() + 0x5e bytes   
system.windows.forms.dll!System.Windows.Forms.DataGrid::DataSource_Changed(System.Object
sender = {System.Windows.Forms.CurrencyManager}, System.EventArgs ea =
{System.EventArgs}) + 0x143 bytes   
system.windows.forms.dll!System.Windows.Forms.DataGrid::DataSource_ItemChanged(System.Object
sender = {System.Windows.Forms.CurrencyManager},
System.Windows.Forms.ItemChangedEventArgs ea = {Index=-1}) + 0x3d bytes    system.windows.forms.dll!System.Windows.Forms.CurrencyManager::OnItemChanged(System.Windows.Forms.ItemChangedEventArgs e = {Index=-1}) + 0xa4 bytes    system.windows.forms.dll!System.Windows.Forms.CurrencyManager::UpdateIsBinding(bool force = false) + 0x12d bytes    system.windows.forms.dll!System.Windows.Forms.CurrencyManager::UpdateIsBinding() + 0x11 bytes   
system.windows.forms.dll!System.Windows.Forms.CurrencyManager::List_ListChanged(System.Object
sender = {System.Data.DataView}, System.ComponentModel.ListChangedEventArgs e
= {System.ComponentModel.ListChangedEventArgs}) + 0x159 bytes   
system.data.dll!System.Data.DataView::OnListChanged(System.ComponentModel.ListChangedEventArgs
e = {System.ComponentModel.ListChangedEventArgs}) + 0x48 bytes   
system.data.dll!System.Data.DataView::IndexListChanged(System.Object sender
= {System.Data.Index}, System.ComponentModel.ListChangedEventArgs e =
{System.ComponentModel.ListChangedEventArgs}) + 0x43 bytes   
system.data.dll!System.Data.DataView::FireEvent(System.Data.TargetEvent
targetEvent = IndexListChanged, System.Object sender = {System.Data.Index},
System.EventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x4c
bytes   
system.data.dll!System.Data.DataViewListener::IndexListChanged(System.Object
sender = {System.Data.Index}, System.ComponentModel.ListChangedEventArgs e =
{System.ComponentModel.ListChangedEventArgs}) + 0x3d bytes    system.data.dll!System.Data.Index::OnListChanged(System.ComponentModel.ListChangedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x29 bytes   
system.data.dll!System.Data.Index::Reset() + 0x1c bytes   
system.data.dll!System.Data.DataTable::EndLoadData() + 0xc1 bytes   
Show quoteHide quote
>FloorsTest.exe!FloorsTest.Maze.FillResultsDataGrid() Line 805    C#

Author
9 Mar 2006 8:43 PM
Peter Bromberg [C# MVP]
Try doing it without the BeginLoadData()
and EndLoadData()  calls, e.g.:

for(int i = 0; i < _movesArrayList.Count; i++)
{
string[] columnValues = ((string)_movesArrayList[i]).Split(COL_SEPARATOR);
DataRow _moveRow = dt.NewRow();
_moveRow[0] = columnValues[0];
_moveRow[1] = columnValues[1];
_moveRow[2] = columnValues[2];
dt.Rows.Add(_moveRow);
}

Yes, I know it's supposed to be faster, but if it blows up, its not good for
anything IMHO.

See if it doesn't go away. Seen this one once before, have no idea why it
happens.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Show quoteHide quote
"Flack" wrote:

> I have a DataGrid and a DataTable.  When my form loads I create the DataTable
> with the appropriate columns and use it for the DataGrids.DataSource.
>
> Later on in my app, I alter the DataTable:
>
> dt.BeginLoadData(); 
> for(int i = 0; i < _movesArrayList.Count; i++)
> {
>    string[] columnValues = ((string)_movesArrayList[i]).Split(COL_SEPARATOR);
>    DataRow _moveRow = dt.NewRow();
>    _moveRow[0] = columnValues[0];
>    _moveRow[1] = columnValues[1];
>    _moveRow[2] = columnValues[2];
>    dt.Rows.Add(_moveRow);
> }         
> dt.EndLoadData();
>
>
> The thing is, every once in a while my app crashes and I get the following
> error:
>
> A first chance exception of type 'System.NullReferenceException' occurred in
> system.windows.forms.dll
> Additional information: Object reference not set to an instance of an object.
>
> According to the stack trace it occurs at dt.EndLoadData() and in the method
>
> System.Windows.Forms.DataGridToolTip::CreateToolTipHandle()
>
> I can't reliably reproduce it.  Has anyone seen anyhting like this before?
>
> Thanks.
>
> Following is the stack trace:
> system.windows.forms.dll!System.Windows.Forms.DataGridToolTip::CreateToolTipHandle() + 0x160 bytes   
> system.windows.forms.dll!System.Windows.Forms.DataGrid::ResetToolTip() +
> 0x44 bytes   
> system.windows.forms.dll!System.Windows.Forms.DataGrid::OnLayout(System.Windows.Forms.LayoutEventArgs
> levent = {System.Windows.Forms.LayoutEventArgs}) + 0xa7 bytes   
> system.windows.forms.dll!System.Windows.Forms.Control::PerformLayout(System.Windows.Forms.Control
> affectedControl = null, String* affectedProperty = null) + 0x7b bytes   
> system.windows.forms.dll!System.Windows.Forms.Control::PerformLayout() +
> 0x13 bytes   
> system.windows.forms.dll!System.Windows.Forms.DataGrid::ResetUIState() +
> 0x34 bytes   
> system.windows.forms.dll!System.Windows.Forms.DataGrid::SetDataGridRows(System.Windows.Forms.DataGridRow[]
> newRows = null, __int32 newRowsLength = 212) + 0x7e bytes   
> system.windows.forms.dll!System.Windows.Forms.DataGrid::RecreateDataGridRows() + 0x5e bytes   
> system.windows.forms.dll!System.Windows.Forms.DataGrid::DataSource_Changed(System.Object
> sender = {System.Windows.Forms.CurrencyManager}, System.EventArgs ea =
> {System.EventArgs}) + 0x143 bytes   
> system.windows.forms.dll!System.Windows.Forms.DataGrid::DataSource_ItemChanged(System.Object
> sender = {System.Windows.Forms.CurrencyManager},
> System.Windows.Forms.ItemChangedEventArgs ea = {Index=-1}) + 0x3d bytes   
> system.windows.forms.dll!System.Windows.Forms.CurrencyManager::OnItemChanged(System.Windows.Forms.ItemChangedEventArgs e = {Index=-1}) + 0xa4 bytes   
> system.windows.forms.dll!System.Windows.Forms.CurrencyManager::UpdateIsBinding(bool force = false) + 0x12d bytes   
> system.windows.forms.dll!System.Windows.Forms.CurrencyManager::UpdateIsBinding() + 0x11 bytes   
> system.windows.forms.dll!System.Windows.Forms.CurrencyManager::List_ListChanged(System.Object
> sender = {System.Data.DataView}, System.ComponentModel.ListChangedEventArgs e
> = {System.ComponentModel.ListChangedEventArgs}) + 0x159 bytes   
> system.data.dll!System.Data.DataView::OnListChanged(System.ComponentModel.ListChangedEventArgs
> e = {System.ComponentModel.ListChangedEventArgs}) + 0x48 bytes   
> system.data.dll!System.Data.DataView::IndexListChanged(System.Object sender
> = {System.Data.Index}, System.ComponentModel.ListChangedEventArgs e =
> {System.ComponentModel.ListChangedEventArgs}) + 0x43 bytes   
> system.data.dll!System.Data.DataView::FireEvent(System.Data.TargetEvent
> targetEvent = IndexListChanged, System.Object sender = {System.Data.Index},
> System.EventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x4c
> bytes   
> system.data.dll!System.Data.DataViewListener::IndexListChanged(System.Object
> sender = {System.Data.Index}, System.ComponentModel.ListChangedEventArgs e =
> {System.ComponentModel.ListChangedEventArgs}) + 0x3d bytes   
> system.data.dll!System.Data.Index::OnListChanged(System.ComponentModel.ListChangedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x29 bytes   
> system.data.dll!System.Data.Index::Reset() + 0x1c bytes   
> system.data.dll!System.Data.DataTable::EndLoadData() + 0xc1 bytes   
> >FloorsTest.exe!FloorsTest.Maze.FillResultsDataGrid() Line 805    C#
>
Are all your drivers up to date? click for free checkup

Author
9 Mar 2006 9:21 PM
Flack
I tried removing the BeginLoadData() and EndLoadData() and now I get a
different error but still at
system.windows.forms.dll!System.Windows.Forms.DataGridToolTip::CreateToolTipHandle() + 0x160 bytes

The error is:

A first chance exception of type
'System.Runtime.InteropServices.SEHException' occurred in
system.windows.forms.dll
Additional information: External component has thrown an exception.

This error occurs in dt.Rows.Add(_moveRow);

I've never seen such an error before.  Also, if I have to fill the grid
without using Begin and EndLoadData (and I have many rows to add) it's going
to be pretty slow and that would suck.

Show quoteHide quote
"Peter Bromberg [C# MVP]" wrote:

> Try doing it without the BeginLoadData()
> and EndLoadData()  calls, e.g.:
>
> for(int i = 0; i < _movesArrayList.Count; i++)
> {
> string[] columnValues = ((string)_movesArrayList[i]).Split(COL_SEPARATOR);
> DataRow _moveRow = dt.NewRow();
> _moveRow[0] = columnValues[0];
> _moveRow[1] = columnValues[1];
> _moveRow[2] = columnValues[2];
> dt.Rows.Add(_moveRow);
> }
>
> Yes, I know it's supposed to be faster, but if it blows up, its not good for
> anything IMHO.
>
> See if it doesn't go away. Seen this one once before, have no idea why it
> happens.
> Peter
>
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
>
>
> "Flack" wrote:
>
> > I have a DataGrid and a DataTable.  When my form loads I create the DataTable
> > with the appropriate columns and use it for the DataGrids.DataSource.
> >
> > Later on in my app, I alter the DataTable:
> >
> > dt.BeginLoadData(); 
> > for(int i = 0; i < _movesArrayList.Count; i++)
> > {
> >    string[] columnValues = ((string)_movesArrayList[i]).Split(COL_SEPARATOR);
> >    DataRow _moveRow = dt.NewRow();
> >    _moveRow[0] = columnValues[0];
> >    _moveRow[1] = columnValues[1];
> >    _moveRow[2] = columnValues[2];
> >    dt.Rows.Add(_moveRow);
> > }         
> > dt.EndLoadData();
> >
> >
> > The thing is, every once in a while my app crashes and I get the following
> > error:
> >
> > A first chance exception of type 'System.NullReferenceException' occurred in
> > system.windows.forms.dll
> > Additional information: Object reference not set to an instance of an object.
> >
> > According to the stack trace it occurs at dt.EndLoadData() and in the method
> >
> > System.Windows.Forms.DataGridToolTip::CreateToolTipHandle()
> >
> > I can't reliably reproduce it.  Has anyone seen anyhting like this before?
> >
> > Thanks.
> >
> > Following is the stack trace:
> > system.windows.forms.dll!System.Windows.Forms.DataGridToolTip::CreateToolTipHandle() + 0x160 bytes   
> > system.windows.forms.dll!System.Windows.Forms.DataGrid::ResetToolTip() +
> > 0x44 bytes   
> > system.windows.forms.dll!System.Windows.Forms.DataGrid::OnLayout(System.Windows.Forms.LayoutEventArgs
> > levent = {System.Windows.Forms.LayoutEventArgs}) + 0xa7 bytes   
> > system.windows.forms.dll!System.Windows.Forms.Control::PerformLayout(System.Windows.Forms.Control
> > affectedControl = null, String* affectedProperty = null) + 0x7b bytes   
> > system.windows.forms.dll!System.Windows.Forms.Control::PerformLayout() +
> > 0x13 bytes   
> > system.windows.forms.dll!System.Windows.Forms.DataGrid::ResetUIState() +
> > 0x34 bytes   
> > system.windows.forms.dll!System.Windows.Forms.DataGrid::SetDataGridRows(System.Windows.Forms.DataGridRow[]
> > newRows = null, __int32 newRowsLength = 212) + 0x7e bytes   
> > system.windows.forms.dll!System.Windows.Forms.DataGrid::RecreateDataGridRows() + 0x5e bytes   
> > system.windows.forms.dll!System.Windows.Forms.DataGrid::DataSource_Changed(System.Object
> > sender = {System.Windows.Forms.CurrencyManager}, System.EventArgs ea =
> > {System.EventArgs}) + 0x143 bytes   
> > system.windows.forms.dll!System.Windows.Forms.DataGrid::DataSource_ItemChanged(System.Object
> > sender = {System.Windows.Forms.CurrencyManager},
> > System.Windows.Forms.ItemChangedEventArgs ea = {Index=-1}) + 0x3d bytes   
> > system.windows.forms.dll!System.Windows.Forms.CurrencyManager::OnItemChanged(System.Windows.Forms.ItemChangedEventArgs e = {Index=-1}) + 0xa4 bytes   
> > system.windows.forms.dll!System.Windows.Forms.CurrencyManager::UpdateIsBinding(bool force = false) + 0x12d bytes   
> > system.windows.forms.dll!System.Windows.Forms.CurrencyManager::UpdateIsBinding() + 0x11 bytes   
> > system.windows.forms.dll!System.Windows.Forms.CurrencyManager::List_ListChanged(System.Object
> > sender = {System.Data.DataView}, System.ComponentModel.ListChangedEventArgs e
> > = {System.ComponentModel.ListChangedEventArgs}) + 0x159 bytes   
> > system.data.dll!System.Data.DataView::OnListChanged(System.ComponentModel.ListChangedEventArgs
> > e = {System.ComponentModel.ListChangedEventArgs}) + 0x48 bytes   
> > system.data.dll!System.Data.DataView::IndexListChanged(System.Object sender
> > = {System.Data.Index}, System.ComponentModel.ListChangedEventArgs e =
> > {System.ComponentModel.ListChangedEventArgs}) + 0x43 bytes   
> > system.data.dll!System.Data.DataView::FireEvent(System.Data.TargetEvent
> > targetEvent = IndexListChanged, System.Object sender = {System.Data.Index},
> > System.EventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x4c
> > bytes   
> > system.data.dll!System.Data.DataViewListener::IndexListChanged(System.Object
> > sender = {System.Data.Index}, System.ComponentModel.ListChangedEventArgs e =
> > {System.ComponentModel.ListChangedEventArgs}) + 0x3d bytes   
> > system.data.dll!System.Data.Index::OnListChanged(System.ComponentModel.ListChangedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x29 bytes   
> > system.data.dll!System.Data.Index::Reset() + 0x1c bytes   
> > system.data.dll!System.Data.DataTable::EndLoadData() + 0xc1 bytes   
> > >FloorsTest.exe!FloorsTest.Maze.FillResultsDataGrid() Line 805    C#
> >

Bookmark and Share