Windows Develop Bookmark and Share   
 index > Windows Forms General > Set accessor is not called for Byte[]
 

Set accessor is not called for Byte[]

I have a member variable, Byte[] _ByteArray, that is displayed in a PropertyGrid control. The Get accessor always seems to get called, but the Set accessor never does. Why is this? After I change a value using the PropGrid, the Set is not called.

Code Snippet

[TypeConverter(typeof(ExpandableObjectConverter))]
class TextTypeContainer
{
private Byte[] _ByteArray;

public TextTypeContainer(String strText1)
{
_ByteArray = new Byte[strText1.Length];
}

[Browsable(true)]
[NotifyParentProperty(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
public Byte[] ByteArray
{
get
{
return _ByteArray;
}
set
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
_strText = encoding.GetString(value);
_ByteArray = value;
}
}
}


Thanks for your help!




Lucky789  Thursday, January 24, 2008 5:52 PM
Hi,

I have just tried your sample. If you modify an element of the array, this is normal that no new array is created. The modification has been done in place. Therefore, your set method is not called. However, if you use the array Editor, it will always create a new array instance and your set method is called. Do you experience something different?

Best regards,


Nicolas Cadilhac @ VisualHint
Smart PropertyGrid.Net
Microsoft PropertyGrid Resource List
Free PropertyGrid for MFC
Smart FieldPackEditor.Net / DateTimePicker

VisualHint  Thursday, January 24, 2008 8:31 PM
Hi,

I have just tried your sample. If you modify an element of the array, this is normal that no new array is created. The modification has been done in place. Therefore, your set method is not called. However, if you use the array Editor, it will always create a new array instance and your set method is called. Do you experience something different?

Best regards,


Nicolas Cadilhac @ VisualHint
Smart PropertyGrid.Net
Microsoft PropertyGrid Resource List
Free PropertyGrid for MFC
Smart FieldPackEditor.Net / DateTimePicker

VisualHint  Thursday, January 24, 2008 8:31 PM
I seem to be seeing the same thing that you are as well. When I change one of the Byte index values, the Set is not called, which is too bad. I do see the array Editor, but it seems to be read-only, and I can not update a value, therefore my Set accessor is not being called.

One question, what do you mean by "modification has been done in place"? I am pretty new to the PropertyGrid in general and appreciate your help.
Lucky789  Thursday, January 24, 2008 8:55 PM
oops sorry, I was using the array editor. You are using the BinaryEditor, which is different. After looking into its code in Reflector, it seems that his editor is for viewing only.

About "modification has been done in place" I mean that if you edit one byte through the child properties, then the byte is modified in the same array and your set method is not called since no new array has been instanciated.

Best regards,


Nicolas Cadilhac @ VisualHint
Smart PropertyGrid.Net
Microsoft PropertyGrid Resource List
Free PropertyGrid for MFC
Smart FieldPackEditor.Net / DateTimePicker

VisualHint  Thursday, January 24, 2008 9:27 PM
I'm trying to use the ByteEditor that you mentioned. Everything seems to compile fine. When I press the icon, "...", in the PropGrid, I get the error "The method or operation is not implemented". Did I configure it correctly? Below is a modified code snippit.

Code Snippet

[Browsable(true)]
[NotifyParentProperty(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
[Editor(typeof(BinaryEditor),typeof(System.Drawing.Design.UITypeEditor))]
public Byte[] ByteArray
{
get
{
return _ByteArray;
}
set
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
_strText = encoding.GetString(value);
_ByteArray = value;
}
}


Lucky789  Friday, January 25, 2008 1:05 AM
Maybe I was not clear enough. The BinaryEditor is the default one that is triggered for byte[] and that you saw first with the readonly HEX panel. So there is no need to force it.

Best regards,


Nicolas Cadilhac @ VisualHint
Smart PropertyGrid.Net
Microsoft PropertyGrid Resource List
Free PropertyGrid for MFC
Smart FieldPackEditor.Net / DateTimePicker

VisualHint  Friday, January 25, 2008 1:14 AM

You can use google to search for other answers

Custom Search

More Threads

• How to save data in a datagridview to a database?
• How to get created application date?
• Windows Media Player ActiveX Control fails on every second file when streaming MP3s from HTTPS server
• numericUpDown ValueChanged
• Please help me with this case?
• Using Windows Image Acquistion in winforms (working) and then as a activex control (not working)
• using User Interface Process Application Block ??
• Listing all settings
• Drawing multiple circles
• Regarding DataGrid