示例#1
0
 void MultiSelectAdd(Node clickedNode, Keys modifierKeys)
 {
     if (Control.ModifierKeys == Keys.None)
     {
         foreach (Node node in NodesSelection)
         {
             int newrow = NodeCollection.GetVisibleNodeIndex(node);
             InvalidateRow(newrow);
         }
         NodesSelection.Clear();
         NodesSelection.Add(clickedNode);
     }
     if (Control.ModifierKeys == Keys.Shift)
     {
         if (NodesSelection.Count == 0)
         {
             NodesSelection.Add(clickedNode);
         }
         else
         {
             int startrow = NodeCollection.GetVisibleNodeIndex(NodesSelection[0]);
             int currow   = NodeCollection.GetVisibleNodeIndex(clickedNode);
             if (currow > startrow)
             {
                 Node startingNode = NodesSelection[0];
                 NodesSelection.Clear();
                 foreach (Node node in NodeCollection.ForwardNodeIterator(startingNode, clickedNode, true))
                 {
                     NodesSelection.Add(node);
                 }
                 Invalidate();
             }
             if (currow < startrow)
             {
                 Node startingNode = NodesSelection[0];
                 NodesSelection.Clear();
                 foreach (Node node in NodeCollection.ReverseNodeIterator(startingNode, clickedNode, true))
                 {
                     NodesSelection.Add(node);
                 }
                 Invalidate();
             }
         }
     }
     if (Control.ModifierKeys == Keys.Control)
     {
         if (NodesSelection.Contains(clickedNode))
         {
             NodesSelection.Remove(clickedNode);
         }
         else
         {
             NodesSelection.Add(clickedNode);
         }
     }
     InvalidateRow(NodeCollection.GetVisibleNodeIndex(clickedNode));
     FocusedNode = clickedNode;
 }
示例#2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            int hScrollOffset = HScrollValue();
            int remainder     = 0;
            int visiblerows   = MaxVisibleRows(out remainder);

            if (remainder > 0)
            {
                visiblerows++;
            }

            bool drawColumnHeaders = true;

            // draw columns
            if (drawColumnHeaders)
            {
                Rectangle headerRect = e.ClipRectangle;
                Columns.Draw(e.Graphics, headerRect, hScrollOffset);
            }
            // draw vertical grid lines
            if (ViewOptions.ShowGridLines)
            {
                // visible row count
                int remainRows = Nodes.VisibleNodeCount - m_vScroll.Value;
                if (visiblerows > remainRows)
                {
                    visiblerows = remainRows;
                }

                Rectangle fullRect = ClientRectangle;
                if (drawColumnHeaders)
                {
                    fullRect.Y += Columns.Options.HeaderHeight;
                }
                fullRect.Height = visiblerows * RowOptions.ItemHeight;
                Columns.Painter.DrawVerticalGridLines(Columns, e.Graphics, fullRect, hScrollOffset);
            }

            int visibleRowIndex = 0;

            TreeListColumn[] visibleColumns = this.Columns.VisibleColumns;
            int columnsWidth = Columns.ColumnsWidth;

            foreach (Node node in NodeCollection.ForwardNodeIterator(m_firstVisibleNode, true))
            {
                Rectangle rowRect = CalcRowRecangle(visibleRowIndex);
                if (rowRect == Rectangle.Empty || rowRect.Bottom <= e.ClipRectangle.Top || rowRect.Top >= e.ClipRectangle.Bottom)
                {
                    if (visibleRowIndex > visiblerows)
                    {
                        break;
                    }
                    visibleRowIndex++;
                    continue;
                }
                rowRect.X     = RowHeaderWidth() - hScrollOffset;
                rowRect.Width = columnsWidth;

                // draw horizontal grid line for current node
                if (ViewOptions.ShowGridLines)
                {
                    Rectangle r = rowRect;
                    r.X     = RowHeaderWidth();
                    r.Width = columnsWidth - hScrollOffset;
                    m_rowPainter.DrawHorizontalGridLine(e.Graphics, r);
                }

                // draw the current node
                PaintNode(e.Graphics, rowRect, node, visibleColumns, visibleRowIndex);

                // drow row header for current node
                Rectangle headerRect = rowRect;
                headerRect.X     = 0;
                headerRect.Width = RowHeaderWidth();

                int absoluteRowIndex = visibleRowIndex + VScrollValue();
                headerRect.Width = RowHeaderWidth();

                PaintRowHeader(e.Graphics, headerRect, node, absoluteRowIndex == m_hotrow);

                visibleRowIndex++;
            }
        }