private ObjectListSource GetFilterableListSource(Type columnType, string filterStrings)
        {
            ObjectListSource result = null;

            if (!string.IsNullOrEmpty(filterStrings))
            {
                if (columnType.IsEnum)
                {
                    IEnumerable <object> source = from str in filterStrings.Split(new char[]
                    {
                        ','
                    })
                                                  select Enum.Parse(columnType, str);

                    result = new EnumListSource(source.ToArray <object>(), columnType);
                }
                else
                {
                    IEnumerable <string> source2 = from str in filterStrings.Split(new char[]
                    {
                        ','
                    })
                                                   select this.GetLocalizedString(str).ToString();

                    result = new ObjectListSource(source2.ToArray <string>());
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        private Control GetComboBoxEditor(FilterablePropertyDescription filterableProperty)
        {
            ExchangeComboBox exchangeComboBox;

            if (!this.valueTypeEditors.ContainsKey(FilterablePropertyValueEditor.ComboBox))
            {
                exchangeComboBox               = new ExchangeComboBox();
                exchangeComboBox.Name          = "comboBoxValue";
                exchangeComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                exchangeComboBox.FlatStyle     = FlatStyle.System;
                exchangeComboBox.Dock          = DockStyle.Fill;
                exchangeComboBox.TabIndex      = 2;
                this.valueTypeEditors.Add(FilterablePropertyValueEditor.ComboBox, exchangeComboBox);
            }
            else
            {
                exchangeComboBox = (this.valueTypeEditors[FilterablePropertyValueEditor.ComboBox] as ExchangeComboBox);
                exchangeComboBox.DataBindings.Clear();
            }
            ObjectListSource filterableListSource = filterableProperty.FilterableListSource;

            exchangeComboBox.DataSource    = new ArrayList(filterableListSource.GetList());
            exchangeComboBox.DisplayMember = "Text";
            exchangeComboBox.ValueMember   = "Value";
            Binding binding   = new Binding("SelectedValue", this.BindingSource, "Value", true, DataSourceUpdateMode.OnPropertyChanged);
            Type    valueType = filterableProperty.ValueType;

            if (typeof(Enum).IsAssignableFrom(valueType))
            {
                binding.Format += delegate(object sender, ConvertEventArgs e)
                {
                    if (e.Value != null && e.Value.GetType() != valueType)
                    {
                        e.Value = Enum.Parse(valueType, e.Value.ToString());
                    }
                };
            }
            exchangeComboBox.DataBindings.Add(binding);
            return(exchangeComboBox);
        }