Beispiel #1
0
        /// <summary>
        /// Gets a list of selected Dynamics365Field objects.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="provider">The provider.</param>
        /// <param name="value">The value.</param>
        /// <returns>The selected objects.</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IDynamics365EntityFieldsProvider fieldsProvider = (IDynamics365EntityFieldsProvider)context.Instance;
            List <Dynamics365Field>          fields         = fieldsProvider.GetDynamics365EntityFields();

            BindingList <Dynamics365Field> currentValue = (BindingList <Dynamics365Field>)value;

            checkedListBox.Items.Clear();
            checkedListBox.Items.Add("Select All", false);
            checkedListBox.ItemCheck += CheckedListBox_ItemCheck;

            fields.ForEach(field => checkedListBox.Items.Add(field, currentValue.Contains(field)));

            IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            service.DropDownControl(checkedListBox);

            BindingList <Dynamics365Field> checkedFields = new BindingList <Dynamics365Field>();

            for (int itemIndex = 0; itemIndex < checkedListBox.CheckedIndices.Count; itemIndex++)
            {
                if (checkedListBox.CheckedIndices[itemIndex] != 0)
                {
                    Dynamics365Field field = (Dynamics365Field)checkedListBox.CheckedItems[itemIndex];
                    checkedFields.Add(field);
                }
            }

            return(checkedFields);
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            // convert from delimited string to field list
            if (!string.IsNullOrEmpty((string)value))
            {
                string   valueString  = (string)value;
                string[] fieldStrings = valueString.Split(new string[] { FIELD_DELIMITER }, StringSplitOptions.None);

                IDynamics365EntityFieldsProvider provider     = (IDynamics365EntityFieldsProvider)context.Instance;
                List <Dynamics365Field>          entityFields = provider.GetDynamics365EntityFields();
                BindingList <Dynamics365Field>   fields       = new BindingList <Dynamics365Field>();

                foreach (string fieldString in fieldStrings)
                {
                    string           id    = Regex.Match(valueString, CoreUtility.FieldMatchPattern).Groups[1].Value;
                    Dynamics365Field field = entityFields.FirstOrDefault(f => f.LogicalName == id);
                    fields.Add(field);
                }

                return(fields);
            }

            return(base.ConvertFrom(context, culture, value));
        }
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            IDynamics365EntityFieldsProvider provider = (IDynamics365EntityFieldsProvider)context.Instance;

            return(new StandardValuesCollection(provider.GetDynamics365EntityFields()));
        }