Hello,
Apologies if this has been discussed already - I can't find it anywhere so I'm posting it in case it has been missed.
I have downloaded version 2.1.4 of CSLA and the associated Project Tracker. In some code I'm currently writing I am getting an error when working with a bound DataGridView so I tried to reproduce the error in Project Tracker - and I can.
The steps are as follows :-
1) Log into PTracker
2) Open Edit Roles form and double click the name on one of the existing rows.
3) Remove ALL the text from the Name column and click onto another row. The broken rules code fires correctly and the blank row is highlighted as a problem "Name Required". All good so far :)
4) If I go back into the blank name column on the invalid record and enter some text, then hit backspace until all the text is gone from the cell again and then click onto another row then the code crashes out with the following :-
======================================
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="System"
StackTrace:
at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.PushValue(Int32 boundColumnIndex, Int32 columnIndex, Int32 rowIndex, Object value)
at System.Windows.Forms.DataGridViewCell.SetValue(Int32 rowIndex, Object value)
at System.Windows.Forms.DataGridView.PushFormattedValue(DataGridViewCell& dataGridViewCurrentCell, Object formattedValue, Exception& exception)
at System.Windows.Forms.DataGridView.CommitEdit(DataGridViewCell& dataGridViewCurrentCell, DataGridViewDataErrorContexts context, DataGridViewValidateCellInternal validateCell, Boolean fireCellLeave, Boolean fireCellEnter, Boolean fireRowLeave, Boolean fireRowEnter, Boolean fireLeave)
at System.Windows.Forms.DataGridView.CommitEdit(DataGridViewDataErrorContexts context, Boolean forCurrentCellChange, Boolean forCurrentRowChange)
at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti, Boolean isShiftDown, Boolean isControlDown)
at System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)
at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at PTWin.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
======================================
It's got to be a data binding "funny" that I'm not understanding. If anybody out there can reproduce this error and let me know how they fixed it I would be very grateful.
I was thinking of trapping the fact that the column in the DataGridView is null but then again I would have though the broken rules code should handle this fact rather than the data binding failing.
I know there have been issues with data binding but not sure if this is a known one with an easy fix or not.
Thanks
ChrisD
Ok, I've just noticed that starting at step 4 of my description above, it looks like it doesn't matter whether I leave the text I have typed into the blank row there or not. Clicking onto another row with text entered correctly also causes the same error.
It looks as if the data row in the grid has lost it's connection to the object it was bound too and we are seeing a Null Reference problem.
Can anyone reproduce my issue?
Cheers
ChrisD
Morning,
Anybody got an answer for me on this?
Any help that can be offered will be gratefully received and it'll make my 36th birthday even better :)
Thank guys
ChrisD
Aaaah.... you could hear a pin drop; isn't silence wonderful LOL.
Jokes apart has anyone been able to reproduce and fix this one yet?
Cheers
ChrisD
I think the issue is that an empty string is converted to a null/Nothing by the grid, so when you blank the column a Nothing ends up in your field. Then when you try to change it back, your set block throws because mName is Nothing.
I think (though I'm not 100% sure) that this must be an SP1 change in the grid, because I don't recall running into this in the past.
One solution is to use the C#-style coding approach even in VB:
Set(ByVal value As String)
CanWriteProperty(True)
If value Is Nothing Then value = ""
If Not mName.Equals(value) Then
mName = value
PropertyHasChanged()
End If
End Set
Another solution is to use the <> operator:
Set(ByVal value As String)
CanWriteProperty(True)
If mName <> value Then
mName = value
PropertyHasChanged()
End If
End Set
Either solution avoids the issue, though the first solution is probably really the one you should use.
Thanks Rocky :)
I wondered if it was an SP1 related issue as I couldn't imagine you leaving that unresolved in PTracker.
Cheers
ChrisD
Copyright (c) Marimer LLC