Windows Develop Bookmark and Share   
 index > Windows Forms Designer > collection of groups with collection of controls not removing instances of controls from code
 

collection of groups with collection of controls not removing instances of controls from code

This is my problem:

I have a Control derived from scrollablecontrol

in that control i have a collection of Groups

Each Group has among other properties a collection of checkboxes

now the problem is this:

when i remove a checkbox from the group collection of checkboxes all goes well in the code. the checkbox is completely removed from the form designer.

problem comes when i remove the group from the collection.

the group is removed from the collection with no problems but the checkboxes that belong to that group aren't cleared from code so instances of those checkboxes are still left in the form designer.

Anyone know how i can remove this leftovers?

Helder Magalhães  Saturday, February 11, 2006 9:56 PM

NM

Found the solution thanks to this article:

http://www.divil.co.uk/net/articles/designers/collectioncontrols.asp

It was still hard work trying to do something that i don't understand.
Creating designers is a pain in the *** :p

Anyways the solution looks something like this:

Dim c As IComponentChangeService = DirectCast _

(GetService(GetType(IComponentChangeService)), IComponentChangeService)

Dim h As IDesignerHost = DirectCast(GetService(GetType(IDesignerHost)), IDesignerHost)

'If the user is removing one of the Groups

If TypeOf e.Component Is CheckListBoxGroup Then

Dim Group As CheckListBoxGroup = DirectCast(e.Component, CheckListBoxGroup)
For i As Integer = Group.CheckBoxes.Count - 1 To 0 Step -1

Dim chkbox As OmniCheckBox = Group.CheckBoxes(i)
c.OnComponentChanging(chkbox, Nothing)
MyControl.Controls.Remove(chkbox)
h.DestroyComponent(chkbox)
c.OnComponentChanged(chkbox, Nothing, Nothing, Nothing)

Next

End If

'If the user is removing this control then remove all groups

If e.Component Is MyControl Then

Dim MyCheckListBox As OmniCheckedListBox = DirectCast(e.Component, OmniCheckedListBox)

For i As Integer = MyCheckListBox.Items.Count - 1 To 0 Step -1

Dim Group As CheckListBoxGroup = MyCheckListBox.Items(i)
c.OnComponentChanging(Group, Nothing)
MyControl.Items.Remove(Group)
h.DestroyComponent(Group)
c.OnComponentChanged(Group, Nothing, Nothing, Nothing)

Next

End If

Helder Magalhães  Sunday, February 12, 2006 9:34 PM

You can use google to search for other answers

Custom Search

More Threads

• How to set Border for PANEL
• Reference Collection TypeConverter?
• Property For combobox
• Windows Control (Dont know the name)
• VS Designer Removing Control.Add declarations
• Making my own Grid - Problems
• Obsolete properties from forms designer
• Ressources embedded problem with a compilation on the fly
• DragDrop in 2.0 Custom Designer problems
• IPersistComponentSettings