Undo and the PictureEdit Control


Author
Message
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Thanks, Trent!  You got me thinking on the right track.  Much appreciated.

I fixed the problem by adding, like you suggested, a check on the count of the BO.  I introduced it into some code that I originally did not think would be called since the Undo was clicked; however, even after clicking the Undo, the editing state of the BO remains in 'Adding' until the bindings have all been taken care of.  So, here is my simple fix:


private void SketchPictureEdit_EditValueChanged(object sender, EventArgs e)
{
   
if (partsBO1.Count > 0)   <--addition
    {
       
if (partsBO1.EditingState != MicroFour.StrataFrame.Business.BusinessEditingState.Idle)
        {
           
if (SketchPictureEdit.EditValue == (byte[])null)
            {
               
this.partsBO1.sketch = new byte[] { };
                SketchPictureEdit.EditValue =
string.Empty;
            }
        }
    }
}

Have a great day!!
Bill

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
So yup....it is exactly what I said!  You have to take this into account.  When you call Undo, the DevEx control is still bound and so there is no record when the Refresh is called and updates the binding.  This is not a bug, but rather how the underlying binding of .NET and SF works.  In this case, since you are binding to the PictureEdit, you are going to either:

  1. Take a "no count" BO into account in your strong-typed property
  2. Manually update the control instead of binding.

If you want to see how to properly set this up, download the StrataFlix sample as it shows you this exact scenario with either the MoviesBO or the PeopleBO as they both have images that bind to a PictureBox control.

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Nope...don't think so.  Here is my load function:


private void PartsMaintenance_Load(object sender, EventArgs e)
{
   
if (_partindex != 0)
    {
        partsBO1.FillByPrimaryKey(_partindex);
    }

    FillPartDescriptionMRU();
    SetMaxLengths();
}

The BO is not being filled at all unless a partindex is sent as a parameter; otherwise, I have an empty BO.  The user simply clicks 'New'.  Then, the user clicks 'Undo'.  Blam!  Error.  As I mentioned before, this error does not occur if I have records in the BO (e.g. via the browse dialog).

I suppose I could default the window to pull up the last 10 edited parts, or something like that.  This would force the BO to be populated, thereby bypassing an error like this.  That seems like a messy workaround, though. 

I'll keep looking for filters and sorts.
Bill

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
So more than likley you have a filter or sort being set which is causing the CurrentRowIndex to either exceed the records in the BO (which is probably not the case) or you are evaluating (or the bound control) the strong-typed property which is trying to pull a record from the BO but there none.  If you set the Filter of the BO while bound under certain conditions, this can happen.  Just ensure that you take this into account when applying filters or manually changing the contents of the internal data table outside of BO logic.
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Meant to throw this in, too.  Your suspicions are correct.

Inner Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> MicroFour.StrataFrame.Business.BusinessLayerException: The CurrentRow for table '[dbo].[PartsMaster]' could not be evaluated because the CurrentRowIndex is out of range. Business object record count: 0. CurrentRowIndex: -1.
at MicroFour.StrataFrame.Business.BusinessLayer.get_CurrentRow()
at Aspire.Model.PartsBO.set_sketch(Byte[] value)
at Aspire.Engineering.PartsMaintenance.SketchPictureEdit_EditValueChanged(Object sender, EventArgs e)
at DevExpress.XtraEditors.Repository.RepositoryItem.RaiseEditValueChangedCore(EventArgs e)
at DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit.RaiseEditValueChangedCore(EventArgs e)
at DevExpress.XtraEditors.Repository.RepositoryItem.RaiseEditValueChanged(EventArgs e)
at DevExpress.XtraEditors.BaseEdit.RaiseEditValueChanged()
at DevExpress.XtraEditors.BaseEdit.OnEditValueChanged()
at DevExpress.XtraEditors.BaseEdit.OnEditValueChanging(ChangingEventArgs e)
at DevExpress.XtraEditors.BaseEdit.set_EditValue(Object value)

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Stack Trace: at MicroFour.StrataFrame.Business.BusinessLayer.RefreshControl(IBusinessBindable ControlToRefresh, Boolean DataPresent)
at MicroFour.StrataFrame.Business.BusinessLayer.RefreshBoundControls()
at MicroFour.StrataFrame.Business.BusinessLayer.raise_Navigated(NavigatedEventArgs e)
at MicroFour.StrataFrame.Business.BusinessLayer.OnNavigated(NavigatedEventArgs e)
at MicroFour.StrataFrame.Business.BusinessLayer.Navigate(BusinessNavigationDirection Direction, Int32 AbsoluteIndex, Object[] PrimaryKeyValues, Boolean AttemptToCheckRules, Boolean IsRefill)
at MicroFour.StrataFrame.Business.BusinessLayer.RestoreCurrentRowIndex(Boolean RefreshUI)
at MicroFour.StrataFrame.Business.BusinessLayer.UndoByForm(BusinessUndoType UndoType)
at MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.Undo()
at MicroFour.StrataFrame.UI.Windows.Forms.MaintenanceFormToolStrip.cmdUndo_Click(Object sender, EventArgs e)
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
My guess is that you're receiving an InvalidOperationException that is something like "CurrentRowIndex = -1, business object record count = 0." But, without looking at the stack trace to see what's actually throwing the exception, I'm not sure what could be causing it.
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
When you receive that exception, there should also be an inner exception with more detail. The real exception is wrapped in an outer exception that just says that field "suchAndSuch" failed to refresh. If you could post the entire details from the red exception dialog, that would be perfect. If Visual Studio is stopping and not showing the red exception dialog, then force Visual Studio to continue by clicking the green play button, and it should show you the dialog instead of breaking on the exception.
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Some additional information may be helpful...the error does not occur if there are records in the BO.  It only occurs when starting with an empty BO.
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I have a PictureEdit control on a maintenance form.  If a user clicks "New", the form responds properly setting up the window to receive the data.  If the same user then clicks undo (even without doing anything else), he gets the following error:

An error occurred while refreshing the data from field 'PartsBOsketch' to property 'EditValue' on control 'SketchPictureEdit.'

I am using SQL Server 2000 (yes, still) and the field is of type 'image'.  The control works absolutely beautifully in all other contexts, except this one.  What do I make of the error?  How do I solve it?

Btw, my custom field properties are set to: Return Alternate on Null; and, the Null Replacement Value is new byte[] {}.

Thanks,
Bill

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search