Results 1 to 3 of 3

Thread: CollectionForm Add/Remove Buttons

  1. #1
    .NET Framework
    .NET 3.5
    Join Date
    Oct 2010
    Posts
    32
    Reputation
    102

    CollectionForm Add/Remove Buttons

    I have subclassed the CollectionEditor to gain access to the CollectionForm and want to be able to know when the Add or Remove button has been clicked. Here's my subclass:

    Code:
        Imports System.ComponentModel.Design
    
        Public Class MyCollectionEditor
            Inherits CollectionEditor
    
    
            Public Shared bEditingCollection As Boolean = False
    
            Public Delegate Sub MyFormClosedEventHandler(
                ByVal sender As Object,
                ByVal e As FormClosedEventArgs)
    
            Public Event MyFormClosed As MyFormClosedEventHandler
    
            Public Delegate Sub MyFormLoadEventHandler(
                ByVal sender As Object,
                ByVal e As System.EventArgs)
    
            Public Event MyFormLoad As MyFormLoadEventHandler
    
            Public Sub New(ByVal type As Type)
                MyBase.New(type)
            End Sub
    
            Protected Overrides Function CreateCollectionForm() As CollectionForm
                Dim collectionForm As CollectionForm = MyBase.CreateCollectionForm
    
                AddHandler collectionForm.FormClosed, AddressOf Me.collection_FormClosed
                AddHandler collectionForm.Load, AddressOf Me.collection_FormLoad
    
                Return collectionForm
            End Function
    
            Private Sub collection_FormLoad(ByVal sender As Object, ByVal e As System.EventArgs)
                bEditingCollection = True
            End Sub
    
            Private Sub collection_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
                bEditingCollection = False
            End Sub
        End Class

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,214
    Reputation
    2862
    CollectionForm is a MustInherit class and implementations can be different, I can see in the source code that the default implementation (CollectionEditor.CollectionEditorCollectionForm) has these buttons buried down somewhere in TableLayoutPanels, it doesn't seem like one should be able to access them.

    Related to this, when looking around the ObservableCollection<T> Class (System.Collections.ObjectModel) | Microsoft Docs often comes up as suggestion since it "provides notifications when items get added, removed".
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  3. #3
    .NET Framework
    .NET 3.5
    Join Date
    Oct 2010
    Posts
    32
    Reputation
    102

    SOLVED: CollectionForm Add/Remove/Up/Down Buttons

    Reed Kimble from the MSDN forum showed me how to do it for the Add/Remove and from his code I was able to add the Up/Down buttons as well:

    Code:
    Protected Overrides Function CreateCollectionForm() As CollectionForm
        Dim collectionForm As CollectionForm = MyBase.CreateCollectionForm
    
        AddHandler collectionForm.FormClosed, AddressOf Me.collection_FormClosed
        AddHandler collectionForm.Load, AddressOf Me.collection_FormLoad
    
        Dim panel1 = collectionForm.Controls.Item("overArchingTableLayoutPanel").Controls.Item("addRemoveTableLayoutPanel")
        AddHandler panel1.Controls.Item("addButton").Click, AddressOf AddButton_Click
        AddHandler panel1.Controls.Item("removeButton").Click, AddressOf RemoveButton_Click
        Dim panel2 = collectionForm.Controls.Item("overArchingTableLayoutPanel")
        AddHandler panel2.Controls.Item("upButton").Click, AddressOf UpButton_Click
            AddHandler panel2.Controls.Item("downButton").Click, AddressOf DownButton_Click
    
        Return collectionForm
    End Function
    
    Private Sub AddButton_Click(sender As Object, e As EventArgs)
        MessageBox.Show("Add Button Clicked")
    End Sub
    
    Private Sub RemoveButton_Click(sender As Object, e As EventArgs)
        MessageBox.Show("Remove Button Clicked")
    End Sub
    
    Private Sub UpButton_Click(sender As Object, e As EventArgs)
        MessageBox.Show("Up Button Clicked")
    End Sub
    
    Private Sub DownButton_Click(sender As Object, e As EventArgs)
        MessageBox.Show("Down Button Clicked")
    End Sub

Similar Threads

  1. dynamically add and remove controls?
    By Jacobier in forum Windows Forms
    Replies: 1
    Last Post: 11-09-2013, 3:41 AM
  2. listbox add and remove
    By theazza in forum Windows Forms
    Replies: 0
    Last Post: 05-21-2011, 9:33 PM
  3. add or remove things?
    By donavan in forum ADO.NET
    Replies: 1
    Last Post: 04-27-2010, 12:38 PM
  4. Add/Remove Application Problem
    By darkcat02 in forum Deployment
    Replies: 0
    Last Post: 05-25-2009, 11:16 PM
  5. DataGrid and Add/Remove Handler
    By mafrosis in forum Winforms Grids
    Replies: 0
    Last Post: 03-13-2007, 9:29 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •