private void settingSecondaryItemListBoxControl_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
        {
            if (e.Index == 0)
            {
                return;
            }
            CheckedListBoxControl checkList = sender as CheckedListBoxControl;

            if (e.Index < checkList.ItemCount - 1 && e.State == CheckState.Unchecked)
            {
                if (checkList.GetItemChecked(checkList.ItemCount - 1))
                {
                    checkList.SetItemChecked(checkList.ItemCount - 1, false);
                }
            }
            else if (e.Index == checkList.ItemCount - 1)
            {
                if (e.State == CheckState.Checked)
                {
                    checkList.CheckAll();
                }
                else
                {
                    int checkCount = 0;
                    for (int index = 0; index < checkList.ItemCount - 1; index++)
                    {
                        if (checkList.GetItemChecked(index))
                        {
                            checkCount++;
                        }

                        if (checkCount == checkList.ItemCount - 1)
                        {
                            checkList.UnCheckAll();
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public PopupContainerEdit CreateMultipleLookUpEdit(IObject obj, string lookupName, object currentValue)
        {
            var control = new PopupContainerEdit();

            control.Properties.PopupControl = new PopupContainerControl();
            var checkedListBoxControl = new CheckedListBoxControl {
                Dock = DockStyle.Fill, CheckOnClick = true
            };

            checkedListBoxControl.ItemCheck += (sender, args) =>
            {
                if (m_ListUpdated)
                {
                    return;
                }
                m_ListUpdated = true;
                try
                {
                    var items = checkedListBoxControl.DataSource as IList;
                    if (items != null && items.Count > 0)
                    {
                        if (args.Index == 0 && (0L.Equals(((IObject)items[args.Index]).Key)))
                        {
                            if (args.State == CheckState.Checked)
                            {
                                checkedListBoxControl.CheckAll();
                            }
                            else if (args.State == CheckState.Unchecked)
                            {
                                checkedListBoxControl.UnCheckAll();
                            }
                        }
                        else if (0L.Equals(((IObject)items[0]).Key))
                        {
                            checkedListBoxControl.SetItemCheckState(0, CheckState.Indeterminate);
                        }
                    }
                }
                finally
                {
                    m_ListUpdated = false;
                }
            };
            control.Properties.PopupControl.Controls.Add(checkedListBoxControl);
            control.Closed += (sender, args) => SearchPanelHelper.DisplayMultipleText(sender as PopupContainerEdit);
            bool bManualChange = false;
            bool bPopup        = false;

            control.QueryPopUp += (sender, args) =>
            {
                if (!bManualChange)
                {
                    bPopup = true;
                    control.Properties.PopupControl.Width = control.Width - 4;
                    bPopup = false;
                }
            };
            control.Properties.PopupControl.SizeChanged += (sender, args) =>
            {
                if (!bPopup)
                {
                    bManualChange = true;
                }
            };

            //if (items != null)
            //{
            //    list.DataSource = items.items;
            //    list.DisplayMember = items.dataTextField ?? "name";
            //    list.ValueMember = items.dataValueField;
            //}
            PropertyInfo pi = obj.GetType().GetProperty(lookupName);

            if (pi != null)
            {
                object ds      = pi.GetValue(obj, null);
                var    keyName = "idfsBaseReference";
                var    list1   = ds as IList;
                if (list1 != null && list1.Count == 0)
                {
                    control.Enabled = false;
                }
                else
                {
                    keyName = ((ds as IList)[0] as IObject).KeyName;
                }

                checkedListBoxControl.DataSource    = ds;
                checkedListBoxControl.DisplayMember = "ToStringProp";
                checkedListBoxControl.ValueMember   = keyName;
            }


            SearchPanelHelper.DisplayMultipleText(control);
            AddClearButton(control, true);

            return(control);
        }