Click here to Skip to main content
15,923,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone.

First off I'm new to C# and still learning.

I am writing a series of controls the first of which is a Connection Combo Box Control.

The idea is that it looks like a standard ComboBox and populates with the Connection Name and when an item is selected it will pass out a connection string.

The Connection property loads a custom collection editor which adds a new connection item object and contains a description (which shows in the list), server name, user name and password.

The issues I have are as follows:
1) when I add new connection at design time, I cant remove them (they disappear from the list but still display at run-time).
2) when adding items at run-time, they don't show in the list.
3) will probably have more issues but these are the main ones at present.

Code below:

public class ConnectionItem
        public string Description { get; set; }
        public string ServerAddress { get; set; }
        public string Username { get; set; }
        public string Password { get; set; }

        public ConnectionItem() { }
        public ConnectionItem(string Descripption, string ServerAddress, string Username, string Password)
            this.Description = Description;
            this.ServerAddress = ServerAddress;
            this.Username = Username;
            this.Password = Password;

public class MyConnectionCollectionEditor : CollectionEditor
        public MyConnectionCollectionEditor() : base(type: typeof(List<ConnectionItem>)) { }
        protected override object CreateInstance(Type itemType)
            return new ConnectionItem();

public class ConnectionComboBox : System.Windows.Forms.ComboBox
        private List<ConnectionItem> _MyConnections = new List<ConnectionItem>();
        [Editor(typeof(MyConnectionCollectionEditor), typeof(UITypeEditor))]
        public List<ConnectionItem> MyConnections
                return _MyConnections;
                _MyConnections = value;

        public ConnectionComboBox() { }

Does anybody have an idea of what I'm doing wrong (please keep in mind I'm a beginner)


What I have tried:

I have looked around the internet but cant find anything that does quite what I need it to.
Richard Deeming 29-Aug-19 11:38am    
As far as I can see, there's no connection between the MyConnections property and the Items[^] collection.

The Items are what will display at run-time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900