Note that there are some explanatory texts on larger screens.

plurals
  1. POInvalidate Form After CollectionEditor Changes Collection
    primarykey
    data
    text
    <p>I have user control which contains a list of objects called "ToolbarButton". A ToolbarButton represents a user button which will be added to the user control.</p> <p>My class looks like this </p> <pre><code>public partial class Toolbar : UserControl { private MyCollection&lt;ToolbarButton&gt; _buttons = new MyCollection&lt;ToolbarButton&gt;(); public Toolbar() { InitializeComponent(); ToolbarCollectionEditor.toolbar = this; } [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] [Editor(typeof(ToolbarCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))] public MyCollection&lt;ToolbarButton&gt; Buttons { get { return _buttons; } } } </code></pre> <p>As you can see I have also implemented the Collection Editor so that I can modify the list during design time. </p> <p>This all works fine, what I am having a problem with is getting the control to redraw when a change is made to the list. I have tried adding an event to listen for a change to the list of objects (my custom list class called MyCollection) but because the CollectionEditor just seems to rewrite the designer code and not refresh it this didnt work.</p> <p>Can anyone tell me how I can do this? Eventually I would like to be able to click the Add button in the Collection Editor and have the control refresh and show the new buttons I have added.</p> <p>Thanks in advance!</p> <p><strong>Update:</strong></p> <p>I have created my own CollectionEditor</p> <pre><code>class ToolbarCollectionEditor : CollectionEditor { public ToolbarCollectionEditor(Type type) : base(type) { } public static Toolbar toolbar; protected override CollectionForm CreateCollectionForm() { CollectionForm collectionForm = base.CreateCollectionForm(); collectionForm.FormClosed += new FormClosedEventHandler(collectionForm_FormClosed); collectionForm.Load += new EventHandler(collectionForm_Load); if (collectionForm.Controls.Count &gt; 0) { TableLayoutPanel mainPanel = collectionForm.Controls[0] as TableLayoutPanel; if ((mainPanel != null) &amp;&amp; (mainPanel.Controls.Count &gt; 7)) { // Get a reference to the inner PropertyGrid and hook // an event handler to it. PropertyGrid propertyGrid = mainPanel.Controls[5] as PropertyGrid; if (propertyGrid != null) { propertyGrid.PropertyValueChanged += new PropertyValueChangedEventHandler( propertyGrid_PropertyValueChanged); } // Also hook to the Add/Remove TableLayoutPanel buttonPanel = mainPanel.Controls[1] as TableLayoutPanel; if ((buttonPanel != null) &amp;&amp; (buttonPanel.Controls.Count &gt; 1)) { Button addButton = buttonPanel.Controls[0] as Button; if (addButton != null) { addButton.Click += new EventHandler(addButton_Click); } Button removeButton = buttonPanel.Controls[1] as Button; if (removeButton != null) { removeButton.Click += new EventHandler(removeButton_Click); } } } } return collectionForm; } private static void collectionForm_FormClosed(object sender, FormClosedEventArgs e) { toolbar.RedrawButtons(); } private static void collectionForm_Load(object sender, EventArgs e) { } private static void propertyGrid_PropertyValueChanged(object sender, PropertyValueChangedEventArgs e) { } private static void addButton_Click(object sender, EventArgs e) { toolbar.RedrawButtons(); } private static void removeButton_Click(object sender, EventArgs e) { toolbar.RedrawButtons(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload