Deleting an Image from the DevEx 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
The image from the DB displays fine.  I can add/edit the image on the form.  It persists in the DB without errors.

If I choose CUT or DELETE from the context menu, I get a DBNull error popping up.  Of course, this is not expected (is it ever?) since I spent a good chunk of time yesterday wrestling with the null issue and the image.  I thought I had that thing licked.

Ermm

What can I do about the delete/cut process on the pictureedit control?

Thanks,
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
What can I do about the delete/cut process on the pictureedit control?

Well, I am not sure off of the top of my head and will have to setup a test with this control.  Bottom line is that the PictureEdit control is trying to set the property to Null...you really want it to be any empty byte array:

New Byte() {}

Also, you may not want to directly bind to the control.  In this example you may want to handle the Navigated event (or something long those lines) and manually set the Picture (or whatever it is) property of the PictureEdit to avoid this type of error.  Just some ideas.

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
Here is the error:

Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'.

And, here's the code (offending line specified):

private class Field_sketch_Descriptor : MicroFour.StrataFrame.Business.FieldPropertyDescriptor
{
   
public Field_sketch_Descriptor() : base("sketch") { }
   
private System.Type _PropertyType = typeof(System.Byte[]);
   
public override object GetValue(Object component)
    {
       
return ((PartsBO)component).sketch;
    }
   
public override void SetValue(Object component, object Value)
    {
        ((
PartsBO)component).sketch = (System.Byte[])Value;  <---offending line
    }
   
public override System.Type PropertyType
    {
       
get
       
{
           
return this._PropertyType;
        }
    }
   
public override System.Type ComponentType
    {
       
get
       
{
           
return _ComponentType;
        }
    }
}

I must have done something different to my previous data table...like set all null values to an empty byte array, or something.  It worked before my recent re-import of the data.  I'll have to review my records to see what might have happened.

Would you suggest a default value for the 'image' field in a SQL Server data table?  Or, would a null value be acceptable?  If a null is acceptable, how should I handle it in the BO?  Then, how would I handle it in the PictureEdit control?

Thanks!
Bill


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
Without changing my database in any way I added this code:

private void SketchPictureEdit_EditValueChanged(object sender, EventArgs e)
{

   
if (SketchPictureEdit.EditValue == new byte[] {})
    {
       
this.partsBO1.sketch = new byte[] {};
        SketchPictureEdit.EditValue =
string.Empty;
   
}
   
else
   
{
       
this.partsBO1.sketch = (byte[])SketchPictureEdit.EditValue;
    }
}

This works.  I am still running some tests, but at least I have a way around the issue.

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
The first thing that the EditValueChanged event needs to check is the editing state of the BO.  If adding or editing, then the code can run; otherwise, it should skip it.  The editing state will be changed by the following line of code:

this.partsBO1.sketch = (byte[])SketchPictureEdit.EditValue;

That is why my navigation disappeared.  And, also explains the confirmation popup when closing the window.

Whew!  Glad that's over.
Bill

(note: cross-posted on purpose--http://forum.strataframe.net/Topic13453-7-1.aspx)

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
Since this error is happening within the Set, not the Get, it looks like the PictureEdit control is actually passing back a DBNull.Value out of its bound property.  Is there a NullValue property somewhere on the control where you can set what the control considers to be "null" to pass back to the data source?  Some of them allow you to pass back either a DBNull.Value or a "null" (C# keyword) or an empty 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
Nope...no NullValue property that I can discover.  There is a NullText property, but it isn't providing the binding value that I need.

Thanks for the help!
Bill

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
Oh...btw...I removed the following code (in red):

private void SketchPictureEdit_EditValueChanged(object sender, EventArgs e)
{

   
if (SketchPictureEdit.EditValue == new byte[] {})
    {
       
this.partsBO1.sketch = new byte[] {};
        SketchPictureEdit.EditValue =
string.Empty;
   
}
   
else
   
{
       
this.partsBO1.sketch = (byte
[])SketchPictureEdit.EditValue;
    }
}

Since I have the control bound to the data already, this was redundant.  And, it caused other navigation problems at various points in the user experience.

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
Ah...yeah, that could cause an issue Smile  Glad you found it.
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