J
josephbubba
I'm having a problem updating the properties of a control in the
Visual Studio Designer property grid. A summary of the control:
1. I have a control derived from ListBox (ReorderListBox).
2. I have added an additional property (AllowReorder) which when set
to true forces the AllowDrop property to true. (This allows the user
to reorder items in the list box using drag and drop).
3. I marked the AllowReorder property with the
RefreshProperties(RefreshProperties.All) attribute so that whenever
the propert is changed it *should* force the update of all the other
properties.
I have tested the control in a standalone Windows Form application
that has a property grid. Whenever I modify the AllowReorder property
the AllowDrop property is properly updated.
Now the problem:
When I try and do the same thing in the Visual Studio Designer
property grid, a modification to AllowReorder does NOT trigger an
update request for the AllowDrop property.
I've stepped through the code with the debugger. I tried launching
the Visual Studio (devenv.exe) as a debug client to see when other
properties are updated. All of the other properties (I added some
additional properties for testing) are being reread when AllowReorder
is modified.
I even tried overriding the virtual AllowDrop method and adding trace
messages to see if it is called. No luck. It is never called when
used within the Visual Studio designer.
As I mentioned previously, it all works fine when used with a standard
property grid. It just doesn't work within Visual Studio.
I have some theories:
1. Because my class is derived from ListBox, some other attribute is
overriding?
2. Because AllowDrop is virtual the designer doesn't know how to
handle it?
Any ideas would be appreciated.
Thanks in advance.
Some code for reference:
public partial class ReorderListBox : ListBox
{
// private members
private bool _allowReorder = true; // allow reordering by
drag and drop
/// <summary>
/// Constructor
/// </summary>
public ReorderListBox()
{
// forms designer support
InitializeComponent();
// allow drag and drop (otherwise the OnDrag... overrides
below won't get called)
AllowDrop = true;
// only single select mode is currently supported
SelectionMode = SelectionMode.One;
}
// some unrelated code here removed for brevity...
/// <summary>
/// Property to get/set the "allow reordering" logic.
/// </summary>
[Category("Behavior")]
[Description("Indicates whether drag and drop can be used to
reorder items in the listbox.")]
[DefaultValue(true)]
[Browsable(true)]
[RefreshProperties(RefreshProperties.All)]
public bool AllowReorder
{
get
{
return _allowReorder;
}
set
{
if (value) AllowDrop = true; // make sure drag
and drop is enabled
_allowReorder = value;
}
}
}
Visual Studio Designer property grid. A summary of the control:
1. I have a control derived from ListBox (ReorderListBox).
2. I have added an additional property (AllowReorder) which when set
to true forces the AllowDrop property to true. (This allows the user
to reorder items in the list box using drag and drop).
3. I marked the AllowReorder property with the
RefreshProperties(RefreshProperties.All) attribute so that whenever
the propert is changed it *should* force the update of all the other
properties.
I have tested the control in a standalone Windows Form application
that has a property grid. Whenever I modify the AllowReorder property
the AllowDrop property is properly updated.
Now the problem:
When I try and do the same thing in the Visual Studio Designer
property grid, a modification to AllowReorder does NOT trigger an
update request for the AllowDrop property.
I've stepped through the code with the debugger. I tried launching
the Visual Studio (devenv.exe) as a debug client to see when other
properties are updated. All of the other properties (I added some
additional properties for testing) are being reread when AllowReorder
is modified.
I even tried overriding the virtual AllowDrop method and adding trace
messages to see if it is called. No luck. It is never called when
used within the Visual Studio designer.
As I mentioned previously, it all works fine when used with a standard
property grid. It just doesn't work within Visual Studio.
I have some theories:
1. Because my class is derived from ListBox, some other attribute is
overriding?
2. Because AllowDrop is virtual the designer doesn't know how to
handle it?
Any ideas would be appreciated.
Thanks in advance.
Some code for reference:
public partial class ReorderListBox : ListBox
{
// private members
private bool _allowReorder = true; // allow reordering by
drag and drop
/// <summary>
/// Constructor
/// </summary>
public ReorderListBox()
{
// forms designer support
InitializeComponent();
// allow drag and drop (otherwise the OnDrag... overrides
below won't get called)
AllowDrop = true;
// only single select mode is currently supported
SelectionMode = SelectionMode.One;
}
// some unrelated code here removed for brevity...
/// <summary>
/// Property to get/set the "allow reordering" logic.
/// </summary>
[Category("Behavior")]
[Description("Indicates whether drag and drop can be used to
reorder items in the listbox.")]
[DefaultValue(true)]
[Browsable(true)]
[RefreshProperties(RefreshProperties.All)]
public bool AllowReorder
{
get
{
return _allowReorder;
}
set
{
if (value) AllowDrop = true; // make sure drag
and drop is enabled
_allowReorder = value;
}
}
}