/// <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)
        {
            IDynamics365ProcessesProvider processesProvider = (IDynamics365ProcessesProvider)context.Instance;
            List <Dynamics365Process>     fields            = processesProvider.GetProcesses();

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

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

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

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

            service.DropDownControl(checkedListBox);

            BindingList <Dynamics365Process> checkedProcesses = new BindingList <Dynamics365Process>();

            for (int itemIndex = 0; itemIndex < checkedListBox.CheckedIndices.Count; itemIndex++)
            {
                if (checkedListBox.CheckedIndices[itemIndex] != 0)
                {
                    Dynamics365Process process = (Dynamics365Process)checkedListBox.CheckedItems[itemIndex];
                    checkedProcesses.Add(process);
                }
            }

            return(checkedProcesses);
        }
Example #2
0
        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[] processStrings = valueString.Split(new string[] { PROCESS_DELIMITER }, StringSplitOptions.None);

                IDynamics365ProcessesProvider    provider        = (IDynamics365ProcessesProvider)context.Instance;
                List <Dynamics365Process>        entityProcesses = provider.GetProcesses();
                BindingList <Dynamics365Process> processes       = new BindingList <Dynamics365Process>();

                foreach (string processString in processStrings)
                {
                    Guid id = new Guid(Regex.Match(valueString, CoreUtility.FieldMatchPattern).Groups[1].Value);
                    Dynamics365Process process = entityProcesses.FirstOrDefault(p => p.ID == id);
                    processes.Add(process);
                }

                return(processes);
            }

            return(base.ConvertFrom(context, culture, value));
        }