Example #1
0
 public void SelectCells(SelectedCell First, SelectedCell Last)
 {
     SelectCells(First, Last, false);
 }
Example #2
0
        public void SelectCells(SelectedCell First, SelectedCell Last, bool Mul)
        {
            //FirstCell = First;
            if (!Mul)
            {
                table.Rows.Clear();
                this.Invalidate(true);
                idc.Clear();
                getNodeID((TreeListNode)null, idc);//获取当前tree中可见的node
            }

            #region

            for (int i = 1; i <= idc.Count; i++)
            {
                try
                {
                    if (idc[i] == this.GetNodeByVisibleIndex(Last.ID).Id&& !go)
                    {
                        inf = i;
                        go  = true;
                        continue;
                    }
                    if (idc[i] == this.GetNodeByVisibleIndex(First.ID).Id&& !go)
                    {
                        inf = i;
                        go  = true;
                        continue;
                    }
                    if (idc[i] == this.GetNodeByVisibleIndex(Last.ID).Id&& go)
                    {
                        enf = i;
                        go  = false;
                        break;
                    }
                    if (idc[i] == this.GetNodeByVisibleIndex(First.ID).Id&& go)
                    {
                        enf = i;
                        go  = false;
                        break;
                    }
                }
                catch { }
            }
            #endregion
            try
            {
                #region
                if (Last.Col > First.Col)
                {
                    #region 当当前鼠标下面的单元格的列索引小于第一个单元格的列索引时
                    for (int c = this.GetColumnByVisibleIndex(First.Col).VisibleIndex; c < this.GetColumnByVisibleIndex(Last.Col).VisibleIndex + 1; c++)
                    {
                        for (int i = inf; i < enf + 1; i++)
                        {
                            if (inf != 0)
                            {
                                if (!table.Rows.Contains(new object[] { idc[i], c }))
                                {
                                    TreeListNode   node1 = this.GetNodeByVisibleIndex(i - 1);
                                    TreeListColumn col1  = this.GetColumnByVisibleIndex(c);
                                    double         val   = 0;
                                    double.TryParse(node1.GetDisplayText(col1), out val);
                                    this.table.Rows.Add(new object[] { idc[i], c, node1, col1, val });
                                }
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    #region 当当前鼠标下面的单元格的列索引大于第一个单元格的列索引时

                    for (int c = this.GetColumnByVisibleIndex(Last.Col).VisibleIndex; c < this.GetColumnByVisibleIndex(First.Col).VisibleIndex + 1; c++)
                    {
                        for (int i = inf; i < enf + 1; i++)
                        {
                            if (inf != 0)
                            {
                                if (!table.Rows.Contains(new object[] { idc[i], c }))
                                {
                                    TreeListNode   node1 = this.GetNodeByVisibleIndex(i - 1);
                                    TreeListColumn col1  = this.GetColumnByVisibleIndex(c);
                                    double         val   = 0;
                                    double.TryParse(node1.GetDisplayText(col1), out val);
                                    table.Rows.Add(new object[] { idc[i], c, node1, col1 });
                                }
                            }
                        }
                    }
                    #endregion
                }
                #endregion
            }
            catch { }
            this.Invalidate(true);
        }
Example #3
0
        private void TreeGrid_MouseDown(object sender, MouseEventArgs e)
        {
            //每一次点击后,更新字典idc,可优化为数据源改变+从新排序后
            idc.Clear();
            getNodeID((TreeListNode)null, idc);//获取当前tree中可见的node

            #region 当失去焦点后,又重新获得焦点点击时判断是不是按下了Ctrl键
            //当点击的时候获取这个东西
            if (Control.ModifierKeys == Keys.Control)
            {
                isKeyCtrl = true;
            }
            else
            {
                isKeyCtrl = false;
            }
            #endregion

            AllSelect = false;     //丢弃全选状态

            this.Invalidate(true); //重新绘制背景

            isMouseDown = false;   //丢弃鼠标按下状态

            #region 必须是按下鼠标左键,并且选中模式必须是Marquee
            if (e.Button == MouseButtons.Left && SelectMode == SelectModeEnum.Marquee)
            {
                Point p = this.PointToClient(Cursor.Position);
                isMouseDown = true;
                //当鼠标按下准备拖选的时候,如果某格单元格有输入焦点,则不能够进行这个操作
                CellInfo cell = this.ViewInfo.GetHitTest(p).CellInfo;
                if (cell == null || cell.Focused)
                {
                    isMouseDown = false;
                }
                #region 还原未选中状态等
                if (!isKeyCtrl)
                {
                    table.Rows.Clear();
                }
                go    = false;
                index = 0;
                inf   = 1;
                enf   = 0;
                #endregion

                TreeListNode   node = this.ViewInfo.GetHitTest(p).Node;
                TreeListColumn col  = this.ViewInfo.GetHitTest(p).Column;
                //符合选择要求后,把当前单元格记录为第一个单元格
                if (node != null && col != null)
                {
                    FirstCell     = new SelectedCell();
                    FirstCell.Col = col.VisibleIndex;//.ColumnHandle;
                    FirstCell.ID  = node.Id;
                    //重新绘制后,将第一个单元格添加到选中集合
                    if (!table.Rows.Contains(new object[] { node.Id, col.VisibleIndex }))
                    {
                        double val = 0;
                        double.TryParse(node.GetDisplayText(col), out val);
                        table.Rows.Add(new object[] { FirstCell.ID, FirstCell.Col, node, col, val });
                    }
                }
                //else
                //{
                //    FirstCell = null;
                //}
                this.Invalidate(true);
            }
            #endregion
        }