Example #1
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();

            if (e.Index < 0 || e.Index >= Items.Count)
            {
                return;
            }

            object      item   = Items[e.Index];
            GKComboItem ddItem = item as GKComboItem;

            if (ddItem != null)
            {
                int offset = e.Bounds.Left;

                if (ddItem.Image != null)
                {
                    e.Graphics.DrawImage(ddItem.Image, e.Bounds.Left, e.Bounds.Top);
                    offset += ddItem.Image.Width;
                }

                e.Graphics.DrawString(ddItem.Caption, e.Font, new SolidBrush(e.ForeColor),
                                      offset, e.Bounds.Top + 2);
            }
            else
            {
                e.Graphics.DrawString(item.ToString(), e.Font, new SolidBrush(e.ForeColor),
                                      e.Bounds.Left, e.Bounds.Top + 2);
            }
            base.OnDrawItem(e);
        }
Example #2
0
        public static T GetSelectedTag <T>(ComboBox comboBox)
        {
            GKComboItem <T> comboItem = (GKComboItem <T>)comboBox.SelectedValue;
            T itemTag = (T)comboItem.Tag;

            return(itemTag);
        }
Example #3
0
        public T GetSelectedTag <T>()
        {
            object          selectedItem = Control.SelectedValue;
            GKComboItem <T> comboItem    = selectedItem as GKComboItem <T>;
            T itemTag = (comboItem != null) ? comboItem.Tag : default(T);

            return(itemTag);
        }
Example #4
0
        public static T GetSelectedTag <T>(ComboBox comboBox)
        {
            object      selectedItem = comboBox.SelectedItem;
            GKComboItem comboItem    = (GKComboItem)selectedItem;
            T           itemTag      = (T)comboItem.Tag;

            return(itemTag);
        }
Example #5
0
        public static void SetSelectedTag <T>(ComboBox comboBox, T tagValue)
        {
            foreach (object item in comboBox.Items)
            {
                GKComboItem comboItem = (GKComboItem)item;
                T           itemTag   = (T)comboItem.Tag;

                if (tagValue.Equals(itemTag))
                {
                    comboBox.SelectedItem = item;
                    return;
                }
            }
            comboBox.SelectedIndex = 0;
        }
Example #6
0
        public void SetSelectedTag <T>(T tagValue, bool allowDefault = true)
        {
            foreach (object item in Control.Items)
            {
                GKComboItem <T> comboItem = item as GKComboItem <T>;

                if (comboItem != null && object.Equals(comboItem.Tag, tagValue))
                {
                    Control.SelectedValue = item;
                    return;
                }
            }

            if (allowDefault)
            {
                Control.SelectedIndex = 0;
            }
        }
Example #7
0
        public static void SelectComboItem(ListBox listBox, object tag, bool allowDefault)
        {
            for (int i = 0; i < listBox.Items.Count; i++)
            {
                GKComboItem item = listBox.Items[i] as GKComboItem;

                if (item != null && object.Equals(item.Tag, tag))
                {
                    listBox.SelectedIndex = i;
                    return;
                }
            }

            if (allowDefault)
            {
                listBox.SelectedIndex = 0;
            }
        }
Example #8
0
        public static void SetSelectedTag <T>(ComboBox comboBox, T tagValue, bool allowDefault = true)
        {
            foreach (object item in comboBox.Items)
            {
                GKComboItem <T> comboItem = (GKComboItem <T>)item;
                T itemTag = (T)comboItem.Tag;

                if (object.Equals(itemTag, tagValue))
                {
                    comboBox.SelectedValue = item;
                    return;
                }
            }

            if (allowDefault)
            {
                comboBox.SelectedIndex = 0;
            }
        }