Пример #1
0
        public void addFile(string fileName)
        {
            CListSubItem comboBox = new CListSubItem();
            CListSubItem fileNameLabel = new CListSubItem();

            //
            ComboBox box = new ComboBox();
            foreach (object obj in Enum.GetValues(typeof(ListFileType)))
            {
                box.Items.Add(obj);    
            }
            box.DropDownStyle = ComboBoxStyle.DropDownList;
            box.SelectedIndex = 0;
            comboBox.Control = box;

            //
            fileNameLabel.Text = fileName;


            CListItem item = new CListItem();
            item.SubItems.Add(comboBox);
            item.SubItems.Add(fileNameLabel);

            _listFiles.Items.Add(item);
        }
Пример #2
0
        /// <summary>
        ///   Changes in the columns, items or subitems
        /// </summary>
        /// <param name = "ctType"></param>
        /// <param name = "column"></param>
        /// <param name = "item"></param>
        /// <param name = "subItem"></param>
        public ChangedEventArgs(ChangedTypes ctType, CColumn column, CListItem item, CListSubItem subItem)
        {
            Column  = column;
            Item    = item;
            SubItem = subItem;

            m_ctType = ctType;
        }
Пример #3
0
        /// <summary>
        ///   remove an item from the list
        /// </summary>
        /// <param name = "item"></param>
        public void Remove(CListItem item)
        {
            List.Remove(item);

            if (ChangedEvent != null)
            {
                ChangedEvent(this, new ChangedEventArgs(ChangedTypes.ItemCollectionChanged, null, null, null));
            }
        }
Пример #4
0
        /// <summary>
        ///   insert an item into the list at specified index
        /// </summary>
        /// <param name = "nIndex"></param>
        /// <param name = "strItemText"></param>
        /// <returns></returns>
        public CListItem Insert(int nIndex, string strItemText)
        {
            CListItem item = new CListItem(Parent); //GLItem item = new GLItem(Parent);

            item.SubItems[1].Text = strItemText;

            nIndex = Insert(nIndex, item);

            return(item);
        }
Пример #5
0
 /// <summary>
 ///   Clears all selection bits in the item structure
 ///
 ///   this overload is an optimization to stop a redraw on a re-selection
 /// </summary>
 public void ClearSelection(CListItem itemIgnore)
 {
     for (int index = 0; index < List.Count; index++)
     {
         CListItem citem = this[index];
         if (citem != itemIgnore)
         {
             citem.Selected = false; // changed will generate an invalidation by themselves
         }
     }
 }
Пример #6
0
        /// <summary>
        ///   Find the index of a specified item
        /// </summary>
        /// <param name = "item"></param>
        /// <returns></returns>
        public int FindItemIndex(CListItem item) // use -1 to have it start from the beginning of the list
        {
            for (int nIndex = 0; nIndex < Count; nIndex++)
            {
                if (item == this[nIndex])
                {
                    return(nIndex);
                }
            }

            return(-1); // couldn't find it
        }
Пример #7
0
        private bool CompareItems(CListItem item1, CListItem item2, CompareDirection direction)
        {
            // add a numeric compare here also
            bool dir = false;

            if (direction == CompareDirection.GreaterThan)
            {
                dir = true;
            }

            if (SortDirection == SortDirections.SortAscending)
            {
                dir = !dir; // flip it
            }
            if (!NumericCompare)
            {
                if (dir)
                {
                    return(item1.SubItems[SortColumn].Text.CompareTo(item2.SubItems[SortColumn].Text) < 0);
                }
                else
                {
                    return(item1.SubItems[SortColumn].Text.CompareTo(item2.SubItems[SortColumn].Text) > 0);
                }
            }
            else
            {
                try
                {
                    double n1 = Double.Parse(item1.SubItems[SortColumn].Text);
                    double n2 = Double.Parse(item2.SubItems[SortColumn].Text);

                    if (dir)
                    {
                        // compare the numeric values inside the columns
                        return(n1 < n2);
                    }
                    else
                    {
                        return(n1 > n2);
                    }
                }
                catch (Exception ex)
                {
                    // no numeric value (bad bad)
                    Debug.WriteLine(ex.ToString());
                    return(false);
                }
            }
        }
Пример #8
0
        public bool GLLoad(CListItem item, CListSubItem subItem, CListView listctrl)
        {
            m_item = item;
            m_subItem = subItem;
            m_Parent = listctrl;

            Text = subItem.Text;

            Items.Add("i1");
            Items.Add("i2");
            Items.Add("i3");

            return true;
        }
Пример #9
0
        public bool GLLoad(CListItem item, CListSubItem subItem, CListView listctrl)
        {
            m_item    = item;
            m_subItem = subItem;
            m_Parent  = listctrl;

            Text = subItem.Text;

            Items.Add("i1");
            Items.Add("i2");
            Items.Add("i3");

            return(true);
        }
Пример #10
0
        /// <summary>
        ///   Conversion to string
        /// </summary>
        /// <param name = "context"></param>
        /// <param name = "culture"></param>
        /// <param name = "value"></param>
        /// <param name = "destinationType"></param>
        /// <returns></returns>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value,
                                         Type destinationType)
        {
            if (destinationType == typeof(InstanceDescriptor) && value is CListItem)
            {
                CListItem column = (CListItem)value;

                ConstructorInfo ci = typeof(CListItem).GetConstructor(new Type[] { });
                if (ci != null)
                {
                    return(new InstanceDescriptor(ci, null, false));
                }
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
Пример #11
0
        public bool GLLoad(CListItem item, CListSubItem subItem, CListView listctrl)
        // populate this control however you wish with item
        {
            // set the styles you want for this
            BorderStyle = BorderStyle.None;
            AutoSize = false;


            m_item = item;
            m_subItem = subItem;
            m_Parent = listctrl;

            Text = subItem.Text;

            return true; // we don't do any heavy processing in this ctrl so we just return true
        }
Пример #12
0
        public void sort(GLItemCollection items, int low_0, int high_0)
        {
            int lo = low_0;
            int hi = high_0;

            if (lo >= hi)
            {
                return;
            }

            int mid = (lo + hi) / 2;


            sort(items, lo, mid);
            sort(items, mid + 1, hi);


            int end_lo   = mid;
            int start_hi = mid + 1;

            while ((lo <= end_lo) && (start_hi <= hi))
            {
                if (StopRequested)
                {
                    return;
                }

                if (CompareItems(items[lo], items[start_hi], CompareDirection.LessThan))
                {
                    lo++;
                }
                else
                {
                    CListItem T = items[start_hi];
                    for (int k = start_hi - 1; k >= lo; k--)
                    {
                        items[k + 1] = items[k];
                    }

                    items[lo] = T;
                    lo++;
                    end_lo++;
                    start_hi++;
                }
            }
        }
Пример #13
0
        private bool CompareItems(CListItem item1, CListItem item2, CompareDirection direction)
        {
            bool dir = false;

            if (direction == CompareDirection.GreaterThan)
                dir = true;

            if (SortDirection == SortDirections.SortAscending)
                dir = !dir; // flip it


            if (!NumericCompare)
            {
                if (dir)
                    return (item1.SubItems[SortColumn].Text.CompareTo(item2.SubItems[SortColumn].Text) < 0);
                else
                    return (item1.SubItems[SortColumn].Text.CompareTo(item2.SubItems[SortColumn].Text) > 0);
            }
            else
            {
                try
                {
                    double n1 = Double.Parse(item1.SubItems[SortColumn].Text);
                    double n2 = Double.Parse(item2.SubItems[SortColumn].Text);


                    if (dir)
                        return (n1 < n2);
                    else
                        return (n1 > n2);
                }
                catch (Exception ex)
                {
                    // no numeric value (bad bad)
                    Debug.WriteLine(ex.ToString());
                    return false;
                }
            }
        }
Пример #14
0
        /// <summary>
        ///   lowest level of add/insert.  All add and insert routines eventually call this
        ///
        ///   in the future always have routines call this one as well to keep one point of entry
        /// </summary>
        /// <param name = "nIndex"></param>
        /// <param name = "item"></param>
        /// <returns></returns>
        public int Insert(int nIndex, CListItem item)
        {
            item.Parent = Parent;

            item.ChangedEvent += Item_Changed;

            if (nIndex < 0)
            {
                nIndex = List.Add(item); // add the item itself
            }
            else
            {
                List.Insert(nIndex, item);
            }

            if (ChangedEvent != null)
            {
                ChangedEvent(this, new ChangedEventArgs(ChangedTypes.ItemCollectionChanged, null, null, null));
            }

            return(nIndex);
        }
Пример #15
0
        public bool GLLoad(CListItem item, CListSubItem subItem, CListView listctrl)
        {
            Format = DateTimePickerFormat.Long;
            try
            {
                m_item = item;
                m_subItem = subItem;
                m_Parent = listctrl;

                Text = subItem.Text;

                //this.Value = subItem.Text;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());

                Text = DateTime.Now.ToString();
            }

            return true;
        }
Пример #16
0
 /// <summary>
 ///   add an itemto the items collection
 /// </summary>
 /// <param name = "item"></param>
 /// <returns></returns>
 public int Add(CListItem item)
 {
     return(Insert(-1, item));
 }
Пример #17
0
        /// <summary>
        ///   Changes in the columns, items or subitems
        /// </summary>
        /// <param name = "ctType"></param>
        /// <param name = "column"></param>
        /// <param name = "item"></param>
        /// <param name = "subItem"></param>
        public ChangedEventArgs(ChangedTypes ctType, CColumn column, CListItem item, CListSubItem subItem)
        {
            Column = column;
            Item = item;
            SubItem = subItem;

            m_ctType = ctType;
        }
Пример #18
0
        /// <summary>
        ///   Find the index of a specified item
        /// </summary>
        /// <param name = "item"></param>
        /// <returns></returns>
        public int FindItemIndex(CListItem item) // use -1 to have it start from the beginning of the list
        {
            for (int nIndex = 0; nIndex < Count; nIndex++)
                if (item == this[nIndex])
                    return nIndex;

            return -1; // couldn't find it
        }
Пример #19
0
 /// <summary>
 ///   Clears all selection bits in the item structure
 /// 
 ///   this overload is an optimization to stop a redraw on a re-selection
 /// </summary>
 public void ClearSelection(CListItem itemIgnore)
 {
     for (int index = 0; index < List.Count; index++)
     {
         CListItem citem = this[index];
         if (citem != itemIgnore)
             citem.Selected = false; // changed will generate an invalidation by themselves
     }
 }
Пример #20
0
        /// <summary>
        ///   remove an item from the list
        /// </summary>
        /// <param name = "item"></param>
        public void Remove(CListItem item)
        {
            List.Remove(item);

            if (ChangedEvent != null)
                ChangedEvent(this, new ChangedEventArgs(ChangedTypes.ItemCollectionChanged, null, null, null));
        }
Пример #21
0
        /// <summary>
        ///   lowest level of add/insert.  All add and insert routines eventually call this
        /// 
        ///   in the future always have routines call this one as well to keep one point of entry
        /// </summary>
        /// <param name = "nIndex"></param>
        /// <param name = "item"></param>
        /// <returns></returns>
        public int Insert(int nIndex, CListItem item)
        {
            item.Parent = Parent;

            item.ChangedEvent += Item_Changed;

            if (nIndex < 0)
                nIndex = List.Add(item); // add the item itself
            else
                List.Insert(nIndex, item);

            if (ChangedEvent != null)
                ChangedEvent(this, new ChangedEventArgs(ChangedTypes.ItemCollectionChanged, null, null, null));

            return nIndex;
        }
Пример #22
0
        /// <summary>
        ///   insert an item into the list at specified index
        /// </summary>
        /// <param name = "nIndex"></param>
        /// <param name = "strItemText"></param>
        /// <returns></returns>
        public CListItem Insert(int nIndex, string strItemText)
        {
            CListItem item = new CListItem(Parent); //GLItem item = new GLItem(Parent);
            item.SubItems[1].Text = strItemText;

            nIndex = Insert(nIndex, item);

            return item;
        }
Пример #23
0
 /// <summary>
 ///   add an itemto the items collection
 /// </summary>
 /// <param name = "item"></param>
 /// <returns></returns>
 public int Add(CListItem item)
 {
     return Insert(-1, item);
 }
Пример #24
0
        /// <summary>
        /// Use the built in sorting mechanism to sort the list
        /// </summary>
//		public void Sort()
//		{
//			this.InnerList.Sort();
//		}
#endif

        /// <summary>
        ///   Compatability with collection editor
        /// </summary>
        /// <param name = "items"></param>
        public void AddRange(CListItem[] items)
        {
            lock (List.SyncRoot)
            {
                for (int i = 0; i < items.Length; i++)
                    Add(items[i]);
            }
        }
Пример #25
0
        /// <summary>
        ///   Instance the activated embeddec control for this item/column
        /// </summary>
        /// <param name = "nColumn"></param>
        /// <param name = "item"></param>
        /// <param name = "subItem"></param>
        protected void ActivateEmbeddedControl(int nColumn, CListItem item, CListSubItem subItem)
        {
            if (m_ActivatedEmbeddedControl != null)
            {
                m_ActivatedEmbeddedControl.Dispose();
                m_ActivatedEmbeddedControl = null;
            }


            /*
			using activator.createinstance
			typeof()/GetType
			Type t = obj.GetType()
			 */

            if (Columns[nColumn].ActivatedEmbeddedControlTemplate == null)
                return;


            Type type = Columns[nColumn].ActivatedEmbeddedControlTemplate.GetType();
            Control control = (Control)Activator.CreateInstance(type);
            CEmbeddedControl icontrol = (CEmbeddedControl)control;

            if (icontrol == null)
                throw new Exception(@"Control does not implement the CEmbeddedControl interface, can't start");

            icontrol.GLLoad(item, subItem, this);


            //control.LostFocus += new EventHandler( ActivatedEmbbed_LostFocus );
            control.KeyPress += tb_KeyPress;

            control.Parent = this;
            ActivatedEmbeddedControl = control;
            //subItem.Control = control;							// seed the control


            int nYOffset = (subItem.LastCellRect.Height - m_ActivatedEmbeddedControl.Bounds.Height) / 2;
            Rectangle controlBounds;

            if (GridLineStyle == GLGridLineStyles.gridNone)
            {
                // add 1 to x to give border, add 2 to Y because to account for possible grid that you must cover up
                controlBounds = new Rectangle(subItem.LastCellRect.X + 1, subItem.LastCellRect.Y + 1,
                                              subItem.LastCellRect.Width - 3, subItem.LastCellRect.Height - 2);
            }
            else
            {
                // add 1 to x to give border, add 2 to Y because to account for possible grid that you must cover up
                controlBounds = new Rectangle(subItem.LastCellRect.X + 1, subItem.LastCellRect.Y + 2,
                                              subItem.LastCellRect.Width - 3, subItem.LastCellRect.Height - 3);
            }
            //control.Bounds = subItem.LastCellRect;	//new Rectangle( subItem.LastCellRect.X, subItem.LastCellRect.Y + nYOffset, subItem.LastCellRect.Width, subItem.LastCellRect.Height );
            control.Bounds = controlBounds;

            control.Show();
            control.Focus();
        }
Пример #26
0
        /// <summary>
        ///   This is an OPTIMIZED routine to see if an item is visible.
        /// 
        ///   The other method of just checking against the item index was slow becuase it had to walk the entire list, which would massively
        ///   slow down the control when large numbers of items were added.
        /// </summary>
        /// <param name = "item"></param>
        /// <returns></returns>
        public bool IsItemVisible(CListItem item)
        {
            // TODO: change this to only walk to visible items list
            int nItemIndex = Items.FindItemIndex(item);
            if ((nItemIndex >= vPanelScrollBar.Value) && (nItemIndex < vPanelScrollBar.Value + VisibleRowsCount))
                return true;

            return false;
        }
Пример #27
0
        /// <summary>
        ///   Draw row at specified coordinates
        /// </summary>
        /// <param name = "graphicsRow"></param>
        /// <param name = "rectRow"></param>
        /// <param name = "item"></param>
        /// <param name = "nItemIndex"></param>
        public virtual void DrawRow(Graphics graphicsRow, Rectangle rectRow, CListItem item, int nItemIndex)
        {
            // row background, if its selected, that trumps all, if not then see if we are using alternating colors, if not draw normal
            // note, this can all be overridden by the sub item background property
            // make sure anything can even be selected before drawing selection rects
            if (item.Selected && Selectable)
            {
                SolidBrush brushBK;
                brushBK = new SolidBrush(Color.FromArgb(255, SelectionColor.R, SelectionColor.G, SelectionColor.B));

                // need to check for full row select here
                if (!FullRowSelect)
                {
                    // calculate how far into the control it goes
                    int nWidthFR = -hPanelScrollBar.Value + Columns.Width;
                    graphicsRow.FillRectangle(brushBK, RowsInnerClientRect.X, rectRow.Y, nWidthFR, rectRow.Height);
                }
                else
                    graphicsRow.FillRectangle(brushBK, RowsInnerClientRect.X, rectRow.Y, RowsInnerClientRect.Width,
                                              rectRow.Height);

                brushBK.Dispose();
            }
            else
            {
                // if the back color of the list doesn't match the back color of the item (AND) the back color isn't white, then override it
                if ((item.BackColor.ToArgb() != BackColor.ToArgb()) && (item.BackColor != Color.White))
                {
                    SolidBrush brushBK = new SolidBrush(item.BackColor);
                    graphicsRow.FillRectangle(brushBK, RowsInnerClientRect.X, rectRow.Y, RowsInnerClientRect.Width,
                                              rectRow.Height);
                    brushBK.Dispose();
                } // check for full row alternate color
                else if (AlternatingColors)
                {
                    // alternating colors are only shown if the row isn't selected
                    int nACItemIndex = Items.FindItemIndex(item);
                    if ((nACItemIndex % 2) > 0)
                    {
                        SolidBrush brushBK = new SolidBrush(AlternateBackground);

                        if (!FullRowSelect)
                        {
                            // calculate how far into the control it goes
                            int nWidthFR = -hPanelScrollBar.Value + Columns.Width;
                            graphicsRow.FillRectangle(brushBK, RowsInnerClientRect.X, rectRow.Y, nWidthFR,
                                                      rectRow.Height);
                        }
                        else
                            graphicsRow.FillRectangle(brushBK, RowsInnerClientRect.X, rectRow.Y,
                                                      RowsInnerClientRect.Width, rectRow.Height);

                        brushBK.Dispose();
                    }
                }
            }


            // draw the row of sub items
            int nXCursor = -hPanelScrollBar.Value + BorderPadding;
            for (int nSubItem = 0; nSubItem < Columns.Count; nSubItem++)
            {
                Rectangle rectSubItem = new Rectangle(nXCursor, rectRow.Y, Columns[nSubItem].Width, rectRow.Height);

                // avoid drawing items that are not in the visible region
                if ((rectSubItem.Right < 0) || (rectSubItem.Left > RowsInnerClientRect.Right))
                    Debug.Write("");
                else
                    DrawSubItem(graphicsRow, rectSubItem, item, item.SubItems[nSubItem], nSubItem);

                nXCursor += Columns[nSubItem].Width;
            }


            // post draw for focus rect and hot tracking
            if ((nItemIndex == HotItemIndex) && HotItemTracking) // handle hot tracking of items
            {
                Color transparentColor = Color.FromArgb(75, HotTrackingColor.R, HotTrackingColor.G, HotTrackingColor.B);
                // 182, 189, 210 );
                Brush hotBrush = new SolidBrush(transparentColor);

                graphicsRow.FillRectangle(hotBrush, RowsInnerClientRect.X, rectRow.Y, RowsInnerClientRect.Width,
                                          rectRow.Height);

                hotBrush.Dispose();
            }


            // draw row borders
            if (item.RowBorderSize > 0)
            {
                Pen penBorder = new Pen(item.RowBorderColor, item.RowBorderSize);
                penBorder.Alignment = PenAlignment.Inset;
                graphicsRow.DrawRectangle(penBorder, rectRow);
                penBorder.Dispose();
            }


            // make sure anything can even be selected before drawing selection rects
            if (Selectable)
                if (ShowFocusRect && (FocusedItem == item)) // deal with focus rect
                    ControlPaint.DrawFocusRectangle(graphicsRow,
                                                    new Rectangle(RowsInnerClientRect.X + 1, rectRow.Y,
                                                                  RowsInnerClientRect.Width - 1, rectRow.Height));
        }
Пример #28
0
        /// <summary>
        ///   Draw Sub Item (Cell) at location specified
        /// </summary>
        /// <param name = "graphicsSubItem"></param>
        /// <param name = "rectSubItem"></param>
        /// <param name = "item"></param>
        /// <param name = "subItem"></param>
        /// <param name = "nColumn"></param>
        public virtual void DrawSubItem(Graphics graphicsSubItem, Rectangle rectSubItem, CListItem item,
                                        CListSubItem subItem, int nColumn)
        {
            // precheck to make sure this is big enough for the things we want to do inside it
            Rectangle subControlRect = new Rectangle(rectSubItem.X, rectSubItem.Y, rectSubItem.Width, rectSubItem.Height);


            if ((subItem.Control != null) && (!subItem.ForceText))
            {
                // custom embedded control here

                Control control = subItem.Control;

                if (control.Parent != this) // *** CRUCIAL *** this makes sure the parent is the list control
                    control.Parent = this;

                //				Rectangle subrc = new Rectangle( 
                //					subControlRect.X+this.CellPaddingSize, 
                //					subControlRect.Y+this.CellPaddingSize, 
                //					subControlRect.Width-this.CellPaddingSize*2,
                //					subControlRect.Height-this.CellPaddingSize*2 );


                Rectangle subrc = new Rectangle(
                    subControlRect.X,
                    subControlRect.Y + 1,
                    subControlRect.Width,
                    subControlRect.Height - 1);


                Type tp = control.GetType();
                PropertyInfo pi = control.GetType().GetProperty("PreferredHeight");
                if (pi != null)
                {
                    int PreferredHeight = (int)pi.GetValue(control, null);

                    if (((PreferredHeight + CellPaddingSize * 2) > ItemHeight) && AutoHeight)
                        ItemHeight = PreferredHeight + CellPaddingSize * 2;

                    subrc.Y = subControlRect.Y + ((subControlRect.Height - PreferredHeight) / 2);
                }

                NewLiveControls.Add(control); // put it in the new list, remove from old list
                if (LiveControls.Contains(control)) // make sure its in the old list first
                {
                    LiveControls.Remove(control); // remove it from list so it doesn't get put down
                }


                if (control.Bounds.ToString() != subrc.ToString())
                    control.Bounds = subrc; // this will force an invalidation

                if (control.Visible != true)
                    control.Visible = true;
            }
            else // not control based
            {
                // if the sub item color is not the same as the back color fo the control, AND the item is not selected, then color this sub item background

                if ((subItem.BackColor.ToArgb() != BackColor.ToArgb()) && (!item.Selected) &&
                    (subItem.BackColor != Color.White))
                {
                    SolidBrush bbrush = new SolidBrush(subItem.BackColor);
                    graphicsSubItem.FillRectangle(bbrush, rectSubItem);
                    bbrush.Dispose();
                }

                // do we need checkboxes in this column or not?
                if (Columns[nColumn].CheckBoxes)
                    rectSubItem = DrawCheckBox(graphicsSubItem, rectSubItem, subItem.Checked);

                // if there is an image, this routine will RETURN with exactly the space left for everything else after the image is drawn (or not drawn due to lack of space)
                if ((subItem.ImageIndex > -1) && (ImageList != null) && (subItem.ImageIndex < ImageList.Images.Count))
                    rectSubItem = DrawCellGraphic(graphicsSubItem, rectSubItem, ImageList.Images[subItem.ImageIndex],
                                                  subItem.ImageAlignment);

                // deal with text color in a box on whether it is selected or not
                Color textColor;
                if (item.Selected && Selectable)
                    textColor = SelectedTextColor;
                else
                {
                    textColor = ForeColor;
                    if (item.ForeColor.ToArgb() != ForeColor.ToArgb())
                        textColor = item.ForeColor;
                    else if (subItem.ForeColor.ToArgb() != ForeColor.ToArgb())
                        textColor = subItem.ForeColor;
                }

                DrawCellText(graphicsSubItem, rectSubItem, subItem.Text, Columns[nColumn].TextAlignment, textColor,
                             item.Selected, ItemWordWrap);

                subItem.LastCellRect = rectSubItem; // important to ONLY catch the area where the text is drawn
            }
        }