D
Daniel Manes
I need a strategy to debug this situation...
I can't put all the code involved, but here are some of the critical
lines with comments:
-------------------------
Private _parentDataCell As DataGridViewCell 'declare private field
_parentDataCell = _parentDataGrid.Rows(rowIndex).Cells(columnIndex)
'set to a specific cell
Debug.Print(_parentDataCell.DataGridView.ToString) 'prints:
System.Windows.Forms.DataGridView
_childDialogResult = _childDialog.ShowDialog() 'show a dialog, user
does certain stuff with dialog
Debug.Print(_parentTableName & " " &
_parentDataCell.DataGridView.ToString) 'throws NullReferenceException
-------------------------
So, the problem is that, somehow, while the user is doing stuff with
the dialog that gets opened, _parentDataCell gets "disembodied"--it's
no longer pointing to a DataGridView. If I do "? _parentDataCell" in
the Immediate window, I get the following:
-------------------------
? _parentDataCell
{System.Windows.Forms.DataGridViewButtonCell}
System.Windows.Forms.DataGridViewButtonCell:
{System.Windows.Forms.DataGridViewButtonCell}
AccessibilityObject:
{System.Windows.Forms.DataGridViewButtonCell.DataGridViewButtonCellAccessibleObject}
ColumnIndex: 2
ContentBounds: {X = 0 Y = 0 Width = 0 Height = 0}
ContextMenuStrip: Nothing
DataGridView: Nothing
DefaultNewRowValue: Nothing
Displayed: False
EditedFormattedValue: Nothing
EditType: Nothing
ErrorIconBounds: {"Cell is not in a DataGridView. The cell cannot
retrieve the inherited cell style."}
ErrorText: ""
FormattedValue: Nothing
FormattedValueType: {Name = "String" FullName = "System.String"}
Frozen: False
HasStyle: False
InheritedState: 80
InheritedStyle: {"Cell is not in a DataGridView. The cell cannot
retrieve the inherited cell style."}
IsInEditMode: False
OwningColumn: {System.Windows.Forms.DataGridViewButtonColumn}
OwningRow: {System.Windows.Forms.DataGridViewRow}
PreferredSize: {Width = -1 Height = -1}
ReadOnly: False
Resizable: False
RowIndex: -1
Selected: False
Size: {Width = -1 Height = -1}
State: None {0}
Style: {System.Windows.Forms.DataGridViewCellStyle}
Tag: Nothing
ToolTipText: ""
Value: Nothing
ValueType: {Name = "String" FullName = "System.String"}
Visible: True
-------------------------
Notice that _parentDataCell is not "Nothing", but it no longer has a
DataGridView, it's dimensions are zero, it's not displayed, etc..
Interestingly, it still has a ColumnIndex of 2, but it's RowIndex is
now -1.
I can't find anything in my code that would be causing this, but
obviously something is. What I need is some way to track or trace
_parentDataCell over time so I can see exactly when it "loses its
identity." Then maybe I'll have some hope of figuring out what's going
on.
How do I do this in Visual Studio 2005?
Any other tips/advice?
Thanks in advance,
-Dan
I can't put all the code involved, but here are some of the critical
lines with comments:
-------------------------
Private _parentDataCell As DataGridViewCell 'declare private field
_parentDataCell = _parentDataGrid.Rows(rowIndex).Cells(columnIndex)
'set to a specific cell
Debug.Print(_parentDataCell.DataGridView.ToString) 'prints:
System.Windows.Forms.DataGridView
_childDialogResult = _childDialog.ShowDialog() 'show a dialog, user
does certain stuff with dialog
Debug.Print(_parentTableName & " " &
_parentDataCell.DataGridView.ToString) 'throws NullReferenceException
-------------------------
So, the problem is that, somehow, while the user is doing stuff with
the dialog that gets opened, _parentDataCell gets "disembodied"--it's
no longer pointing to a DataGridView. If I do "? _parentDataCell" in
the Immediate window, I get the following:
-------------------------
? _parentDataCell
{System.Windows.Forms.DataGridViewButtonCell}
System.Windows.Forms.DataGridViewButtonCell:
{System.Windows.Forms.DataGridViewButtonCell}
AccessibilityObject:
{System.Windows.Forms.DataGridViewButtonCell.DataGridViewButtonCellAccessibleObject}
ColumnIndex: 2
ContentBounds: {X = 0 Y = 0 Width = 0 Height = 0}
ContextMenuStrip: Nothing
DataGridView: Nothing
DefaultNewRowValue: Nothing
Displayed: False
EditedFormattedValue: Nothing
EditType: Nothing
ErrorIconBounds: {"Cell is not in a DataGridView. The cell cannot
retrieve the inherited cell style."}
ErrorText: ""
FormattedValue: Nothing
FormattedValueType: {Name = "String" FullName = "System.String"}
Frozen: False
HasStyle: False
InheritedState: 80
InheritedStyle: {"Cell is not in a DataGridView. The cell cannot
retrieve the inherited cell style."}
IsInEditMode: False
OwningColumn: {System.Windows.Forms.DataGridViewButtonColumn}
OwningRow: {System.Windows.Forms.DataGridViewRow}
PreferredSize: {Width = -1 Height = -1}
ReadOnly: False
Resizable: False
RowIndex: -1
Selected: False
Size: {Width = -1 Height = -1}
State: None {0}
Style: {System.Windows.Forms.DataGridViewCellStyle}
Tag: Nothing
ToolTipText: ""
Value: Nothing
ValueType: {Name = "String" FullName = "System.String"}
Visible: True
-------------------------
Notice that _parentDataCell is not "Nothing", but it no longer has a
DataGridView, it's dimensions are zero, it's not displayed, etc..
Interestingly, it still has a ColumnIndex of 2, but it's RowIndex is
now -1.
I can't find anything in my code that would be causing this, but
obviously something is. What I need is some way to track or trace
_parentDataCell over time so I can see exactly when it "loses its
identity." Then maybe I'll have some hope of figuring out what's going
on.
How do I do this in Visual Studio 2005?
Any other tips/advice?
Thanks in advance,
-Dan