Listbox for assigning property in configuration tool

Topics: Building and extending application blocks, Enterprise Library Core
Oct 11, 2010 at 11:26 AM

What i have:

I have created my new custom section.

I have some string ConfigurationProperty.

All works fine. Now i want configuration console designer to show some suggested values to set this property. For example, com port names.

Instead of manually writing "Com1", i want to have in this field listbox with all installed com ports. How can i do this, where can i assign available values for the field?

Oct 12, 2010 at 1:54 AM

You can create an enumeration value.   For example, if you have a property named ComPorts, you'll create the enumeration:

public enum COMPorts
{
        Com1,
        Com2
}

Your property should then have its type as COMPorts:

public COMPorts ComPort
{
       get { return (COMPorts )this[comPort]; }
       set { this[comPort] = value; }
}

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Oct 12, 2010 at 5:49 AM

But i want to see only available Com ports, so the list is generated dynamically. How to be?

Oct 12, 2010 at 7:09 AM

Currently, I don't see any custom attributes that allows you this.  You may have to create your own custom attribute, something like the ReferenceAttribute.  I'll continue investigating this and let you know if I find out anything.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 12, 2010 at 8:14 AM

maybe i should do something in viewmodel? Because property should be string and get any string value in common. Only when assigning in particular moment of time there should be particular variants.

Oct 14, 2010 at 3:47 AM

You mean it's something like providing an autocomplete functionality?  I'm not sure that the ViewModel would be the appropriate attribute to use so I'm suggesting creating your own custom attribute.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 14, 2010 at 5:59 AM

no, not autocomplete. I mean the property should be string, but when configuring in tool on 1st computer, there should be values (com-ports) only available on this computer, on other computer, suggested values will be other.

Oct 14, 2010 at 6:06 AM

I see.  Still, I don't see any existing classes in entlib that will provide you with this capability.  Your choice would be as I said a custom attribute (no concrete idea as of now how to implement the logic) or probably using a custom editor although I understand that it seems much better if its just going to be provided in a simple dropdown list rather than opening up an editor.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 15, 2010 at 11:23 AM

I have found solution:

#pragma warning disable 1591
    /// <summary>
    /// This class supports block-specific configuration design-time and is not
    /// intended to be used directly from your code.
    /// </summary>
    public class AvailableComNumbers : ElementProperty
    {
        
        public AvailableComNumbers(IServiceProvider serviceProvider, ElementViewModel parent, PropertyDescriptor declaringProperty)
            : base(serviceProvider, parent, declaringProperty)
        {
        }

        public override IEnumerable<object> SuggestedValues
        {
            get
            {
                return System.IO.Ports.SerialPort.GetPortNames();
            }
        }

        public override bool HasSuggestedValues
        {
            get
            {
                return true;
            }
        }
    }

#pragma warning restore 1591

Oct 16, 2010 at 4:46 AM

I've also come across the ElementProperty just now.  Glad it works for you.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com