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.DataG ridViewButtonCellAccessibleObject}
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 3 2267
The easiest thing to do is add the line where you
set _parentDataCell right before you use it again.
But I understand why you would want to know where
it's getting changed.
I thought there was a way to break in debug mode
when the value of a variable changed, but I can't
find it.
So I'd put a breakpoint where you first set
_parentDataCell. When you get there and it stops,
right-click on it and add a Watch on it. Then step
through your code, and watch it in the Watch
window and see when it changes.
It could be that if you are changing rowIndex
and/or columnIndex somewhere, it is redefining
parentDataCell to point at that new location,
although I think that would be unexpected.
Robin S.
------------------
"Daniel Manes" <da******@cox.netwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>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.DataG ridViewButtonCellAccessibleObject}
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
Hey Robin,
Thanks for the reply. I actually managed to solved the problem, but I
still wonder if there would have been an easier way. Some comments
below.
So I'd put a breakpoint where you first set
_parentDataCell. When you get there and it stops,
right-click on it and add a Watch on it. Then step
through your code, and watch it in the Watch
window and see when it changes.
Good idea. Actually what I tried :) But here's the problem: You can
only step through the debugger until all code associated with an event
is run. Then the debugger just stops. It wasn't until several mouse
clicks later that the link was getting lost.
So, I thought: put a break point in click event and keep watching the
value. But there was a problem with that too. The event handlers are in
a different class than _parentDataCell, so _parentDataCell is out of
scope (i.e., you can't see its value in the debugger/watcher).
Also, new instances of the class containing _parentDataCell get created
as the user clicks various buttons, so, how would the watcher know
which _parentDataCell I was talking about anyway?
The only solution I could think of was to create a shared (static)
variable called _firstParentDataCell, and set it equal to
_parentDataCell only if _parentDataCell had not yet been set. Then I
wrote a little shared function that tests to see whether
_firstParentDataCell is still "intact." Finally, I placed calls to the
function strategically through the code to see when the data was
getting lost.
This worked but it sure seemed like a lot of hassle. Turned out, the
bug was caused by one of those user clicks causing the filter on the
original DataGridView to get reapplied. The cell in question was still
there, but the act of refiltering caused all references to go blooey.
So, yeah, programming is hard :)
-Dan
RobinS wrote:
The easiest thing to do is add the line where you
set _parentDataCell right before you use it again.
But I understand why you would want to know where
it's getting changed.
I thought there was a way to break in debug mode
when the value of a variable changed, but I can't
find it.
So I'd put a breakpoint where you first set
_parentDataCell. When you get there and it stops,
right-click on it and add a Watch on it. Then step
through your code, and watch it in the Watch
window and see when it changes.
It could be that if you are changing rowIndex
and/or columnIndex somewhere, it is redefining
parentDataCell to point at that new location,
although I think that would be unexpected.
Robin S.
------------------
"Daniel Manes" <da******@cox.netwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
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.DataG ridViewButtonCellAccessibleObject}
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
It's cool that you figured out what the problem was.
You could also have set ParentDataCell as a property,
but that has the same impact as your solution.
If programming wasn't hard, then anybody could do it,
and it wouldn't be fun any more.
Robin S.
-----------------
"Daniel Manes" <da******@cox.netwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hey Robin,
Thanks for the reply. I actually managed to solved the problem, but I
still wonder if there would have been an easier way. Some comments
below.
>So I'd put a breakpoint where you first set _parentDataCell. When you get there and it stops, right-click on it and add a Watch on it. Then step through your code, and watch it in the Watch window and see when it changes.
Good idea. Actually what I tried :) But here's the problem: You can
only step through the debugger until all code associated with an event
is run. Then the debugger just stops. It wasn't until several mouse
clicks later that the link was getting lost.
So, I thought: put a break point in click event and keep watching the
value. But there was a problem with that too. The event handlers are in
a different class than _parentDataCell, so _parentDataCell is out of
scope (i.e., you can't see its value in the debugger/watcher).
Also, new instances of the class containing _parentDataCell get created
as the user clicks various buttons, so, how would the watcher know
which _parentDataCell I was talking about anyway?
The only solution I could think of was to create a shared (static)
variable called _firstParentDataCell, and set it equal to
_parentDataCell only if _parentDataCell had not yet been set. Then I
wrote a little shared function that tests to see whether
_firstParentDataCell is still "intact." Finally, I placed calls to the
function strategically through the code to see when the data was
getting lost.
This worked but it sure seemed like a lot of hassle. Turned out, the
bug was caused by one of those user clicks causing the filter on the
original DataGridView to get reapplied. The cell in question was still
there, but the act of refiltering caused all references to go blooey.
So, yeah, programming is hard :)
-Dan
RobinS wrote:
>The easiest thing to do is add the line where you set _parentDataCell right before you use it again. But I understand why you would want to know where it's getting changed.
I thought there was a way to break in debug mode when the value of a variable changed, but I can't find it.
So I'd put a breakpoint where you first set _parentDataCell. When you get there and it stops, right-click on it and add a Watch on it. Then step through your code, and watch it in the Watch window and see when it changes.
It could be that if you are changing rowIndex and/or columnIndex somewhere, it is redefining parentDataCell to point at that new location, although I think that would be unexpected.
Robin S. ------------------ "Daniel Manes" <da******@cox.netwrote in message news:11**********************@i42g2000cwa.googleg roups.com...
>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.DataG ridViewButtonCellAccessibleObject}
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: 2G |
last post by:
Hi,
Is there a way to set a cell in a DataGridView invisible? the property in
readonly.
I have some columns with checkboxes but there are some rows that should not
have the checkbox available...
|
by: George |
last post by:
Hi,
I have been encountering a refresh problem with DataGridView, which is bound
to a DataTable.
When I make updates (Add, Delete, update) to the DataGridView, everything
flow nicely to...
|
by: joey.powell |
last post by:
Does anyone know how to access, with code, combo boxes in datagridview
cells? I would like to be able to "load" them with values from say, a
list of strings.
|
by: John J. Hughes II |
last post by:
I am trying to create a custom DataGridViewCell which is "NOT" derived from
DataGridViewTextBoxColumn. The painting works fine but I am unable to get
the control into edit mode.
Do I need to...
|
by: Daniel Manes |
last post by:
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...
|
by: snowjim |
last post by:
Hey!
How do I clone a DataGridViewCell? I Have tested the fallowing:
MyCostomRow row = r.Clone();
for (Int32 index = 0; index < r.Cells.Count; index++)
{
row.Cells =...
|
by: Spam Catcher |
last post by:
Hi all,
I'm trying to set the DataGridViewCell.Value of an unbound column. I can
set the value in code, but the value isn't being displayed.
I tried to RefreshEdit/EndEdit/Invalidate the...
|
by: Robert Koch |
last post by:
Hello!
I'm writing a Windows Application and want to
host different User Controls in a DataGridView.
The Controls are not known during design time, they
could be graphs, comboboxes, curves,...
|
by: JB |
last post by:
Hi Everyone,
I have a DataGridView with Combo Boxes in its cells.
I'd like to know if the user has clicked on the right side arrow
button that triggers the opening of the drop down list.
After...
|
by: JB |
last post by:
Hi All,
I have a DataGridView issue.
One of the columns in my DataGridView control is a combo box. I want
the user to be able to edit the value as well as choosing it from the
drop down list....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |