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))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<ConnectionItem> MyConnections
{
get
{
return _MyConnections;
}
set
{
_MyConnections = value;
}
}
public ConnectionComboBox() { }
}
Does anybody have an idea of what I'm doing wrong (please keep in mind I'm a beginner)
Thanks
What I have tried:
I have looked around the internet but cant find anything that does quite what I need it to.