Example #1
0
 private void UpdateCollections()
 {
     if (CheckedItems != null)
     {
         CheckedItems.Refresh();
     }
     if (CheckedIndices != null)
     {
         CheckedIndices.Refresh();
     }
 }
Example #2
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (Items.Count == 0)
            {
                return;
            }

            var g = e.Graphics;

            using (var brush = new SolidBrush(BackColor))
            {
                g.FillRectangle(brush, 0, e.Bounds.Y, e.Bounds.Width, 16);
            }

            var boxColor = ColorTranslator.FromHtml(BoxColor);

            using (var pen = new Pen(boxColor))
            {
                g.DrawRectangle(pen, 0, e.Bounds.Y + 1, 12, 12);
            }

            if (CheckedIndices.Contains(e.Index))
            {
                using (var brush = new SolidBrush(boxColor))
                {
                    g.FillRectangle(brush, 2, e.Bounds.Y + 3, 9, 9);
                }
            }

            var size = g.MeasureString(Text, Font);

            using (var brush = new SolidBrush(ForeColor))
            {
                g.DrawString(Items[e.Index].ToString(), Font, brush,
                             new Rectangle(16,            // standard icon size
                                           e.Bounds.Y,
                                           e.Bounds.Width - 16,
                                           (int)size.Height),
                             new StringFormat
                {
                    Trimming    = StringTrimming.EllipsisCharacter,
                    FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoWrap
                });
            }
        }
Example #3
0
        public void newItem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            ListViewItemViewModel item = ((ListViewItemViewModel)sender);

            if (item.Selected || item.Focused)
            {
                int index = Items.IndexOf(item);
                if (index > -1)
                {
                    SelectedIndices.Add(index);
                }
            }
            if (item.Checked)
            {
                int index = Items.IndexOf(item);
                if (index > -1)
                {
                    CheckedIndices.Add(index);
                }
            }
        }
 private void OnCaseChecked(object sender, ItemCheckEventArgs e)
 {
     // build list of checked items in chklbCases
     CheckedIndices.Clear();
     foreach (int index in chklbCases.CheckedIndices)
     {
         CheckedIndices.Add(index);
     }
     if (null != e)
     {
         if (e.NewValue == CheckState.Checked)
         {
             CheckedIndices.Add(e.Index);
         }
         else if (e.NewValue == CheckState.Unchecked)
         {
             CheckedIndices.Remove(e.Index);
         }
     }
     UpdateStatus(string.Empty);
     timer.Stop();
     timer.Start();
 }
Example #5
0
        /// <summary>
        /// Adds a new element to the combo
        /// </summary>
        /// <param name="item">item to add</param>
        /// <param name="index">position to adding</param>
        public int AddItem(object item, int index = -1)
        {
            var newItem = CreateItem(item);

            if (index == -1 || index == ListViewItemViewModels.Count)
            {
                ListViewItemViewModels.Add(newItem);
                SortElements();
                ListViewItemViewModels_CollectionChanged();
                if (newItem.Selected)
                {
                    SelectedIndices.Add(newItem.Index);
                }
                if (newItem.Checked)
                {
                    CheckedIndices.Add(newItem.Index);
                }

                return(newItem.Index);
            }
            ListViewItemViewModels.Insert(index, newItem);
            SortElements();
            return(index);
        }
Example #6
0
 private void UpdateCollections()
 {
     CheckedItems.Refresh();
     CheckedIndices.Refresh();
 }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (Items.Count == 0)
            {
                return;                              //sanity check
            }
            IColoredListBoxItem item = (IColoredListBoxItem)Items[e.Index];

            // Draw background
            e.DrawBackground();

            // Draw checkbox
            CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(e.Bounds.Left + 1, e.Bounds.Top + 1), CheckedIndices.Contains(e.Index) ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal);

            // Draw warning icon
            if (item.ShowWarning && WarningIcon != null)
            {
                e.Graphics.DrawImage(WarningIcon, e.Bounds.Left + e.Bounds.Height + 2, e.Bounds.Top, WarningIcon.Width, WarningIcon.Height);
            }
            else             // Draw color rectangle
            {
                using (SolidBrush bg = new SolidBrush(item.Color))
                {
                    e.Graphics.FillRectangle(bg, e.Bounds.Left + e.Bounds.Height + 2, e.Bounds.Top + 2, e.Bounds.Height, e.Bounds.Height - 5);
                }
                using (Pen outline = new Pen(Color.Black))
                {
                    e.Graphics.DrawRectangle(outline, e.Bounds.Left + e.Bounds.Height + 2, e.Bounds.Top + 2, e.Bounds.Height, e.Bounds.Height - 5);
                }
            }

            // Draw text
            int       offset     = e.Bounds.Left + e.Bounds.Height * 2 + 4;
            Rectangle textbounds = new Rectangle(offset, e.Bounds.Top, e.Bounds.Width - offset, e.Bounds.Height);

            e.Graphics.DrawString(item.ToString(), e.Font, new SolidBrush(e.ForeColor), textbounds.Left, textbounds.Top);

            // Draw focus rectangle
            if (e.State == DrawItemState.Focus)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, textbounds, e.ForeColor, e.BackColor);
            }
        }