A non-abstract event defined in an abstract class will not show up in Designer for derived classes

I am using the class below to create a UserControl package for a ComboBox that can take a List <T> and return an object of type T when the ComboBox's internal selection changes.

Everything works fine in the code, exactly as I expect, but I cannot get the SelectedItemChanged event to show up in the Designer anymore when I use my control. It worked great when the abstract base class was not abstract, but I'm trying to condense 5 essentially duplicate controls into one.

Unimportant parts were cut off.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;

namespace UserComboTest
{
    public abstract partial class DropDownList<T> : UserControl where T : class
    {
        protected abstract int FindIndex(T item);
        public abstract void Populate(List<T> items, T defaultItem);

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), Browsable(true)]
        public event EventHandler<SelectedItemEventArgs> SelectedItemChanged;

        private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (null != SelectedItemChanged)
            {
                SelectedItemChanged(this, new SelectedItemEventArgs(Selected));
            }
        }

        public class SelectedItemEventArgs : EventArgs
        {
            public SelectedItemEventArgs(T selectedItem)
            {
                Selected = selectedItem;
            }

            public T Selected { get; private set; }
        }
    }

    public class UserDropDownList : DropDownList<User>
    {
        protected override int FindIndex(User user)
        {
            // find index for item
        }

        public override void Populate(List<User> users, User defaultUser)
        {
            // populate the list
        }
    }
}

      

EDIT . Fixed problem with code. It turned out that both my namespace and form were named UserComboTest, so when he serialized the fully qualified type name (UserComboTest.UserDropDownList), he assumed it was a member or class under the form, not a namespace. In other words, he thought he was looking for UserComboTest.UserComboTest.UserDropDownList, which doesn't exist. Renaming the form to UserComboTest.UserComboTestForm solved half the problem.

There is still the fact that the designer does not show the SelectedItemChanged event and if I manually set it it gets removed, so I need to either set it outside the InitializeComponent or figure out how to get it serialized.

+1


a source to share


1 answer


Generally, a winforms designer is not responsive to abstract base classes. You have to turn abstract methods into empty virtual methods and make the class non-abstract.



+2


a source