Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="startId"></param>
 private void DoResetTagId(int startId)
 {
     if (CurrentSelectTag != null)
     {
         var res = DevelopServiceHelper.Helper.ResetTagIds(GroupModel.Database, new List <int>()
         {
             CurrentSelectTag.Id
         }, startId);
         if (res != null && res.Count > 0)
         {
             CurrentSelectTag.Id = res.First().Value;
         }
     }
     else
     {
         var tags = SelectedCells.Select(e => (e.Item as TagViewModel).Id).ToList();
         var res  = DevelopServiceHelper.Helper.ResetTagIds(GroupModel.Database, new List <int>()
         {
             CurrentSelectTag.Id
         }, startId);
         if (res != null && res.Count > 0)
         {
             foreach (var vv in SelectedCells.Select(e => e.Item).Distinct().ToArray())
             {
                 var vvt = vv as TagViewModel;
                 if (res.ContainsKey(vvt.Id))
                 {
                     vvt.Id = res[vvt.Id];
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 protected override void OnKeyDown(KeyEventArgs e)
 {
     //Expands row if right arrow is pressed
     if (e.KeyData == Keys.Right)
     {
         int totalRowsAdded = 0;
         foreach (var row in SelectedCells.Cast <DataGridViewCell>().Select(o => o.OwningRow).Distinct().OrderByDescending(o => o.Index))
         {
             totalRowsAdded += expand(row.Index, expandedRowList[row.Index].RowIndexHierarchy.Count);
         }
         base.RowCount += totalRowsAdded;
     }
     //Collapses row if left arrow is pressed
     else if (e.KeyData == Keys.Left)
     {
         int totalRowsRemoved = 0;
         foreach (var row in SelectedCells.Cast <DataGridViewCell>().Select(o => o.OwningRow).Distinct().OrderByDescending(o => o.Index))
         {
             totalRowsRemoved += collapse(row.Index);
         }
         base.RowCount -= totalRowsRemoved;
     }
     else
     {
         base.OnKeyDown(e);
         return;
     }
     Refresh();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Assign values to specified property of Model from local DbSet and propagate changes to DGV.
 /// </summary>
 /// <typeparam name="T">Type of Model property</typeparam>
 /// <param name="prop">Name of properrty of Model or Column from dgv</param>
 /// <param name="val">Value</param>
 public void FillDbSetValues <T>(string prop, T val)
 {
     try
     {
         CellValueChanged -= RDataGridView_CellValueChanged;
         foreach (var i in SelectedCells.OfType <DataGridViewCell>().Select(c => c.RowIndex).Where(c => c >= 0).Distinct())
         {
             var m = CurrentDbSet.Where(mm => mm.Id == (int)Rows[i].Cells["Id"].Value).FirstOrDefault();
             if (m == null)
             {
                 continue;
             }
             var setPropValue = m.GetType().GetProperty(prop).GetSetMethod();
             setPropValue.Invoke(m, new object[] { val });
             CurrentDbSet.Update(m);
         }
         SaveChanges();
         Refresh();
         CellValueChanged += RDataGridView_CellValueChanged;
     }
     catch (Exception ex)
     {
         Report.Notify(new RCM.Message(Codes.ERR_UI_WF_FILL_DB_VAL)
         {
             DetailedText = string.Join(Environment.NewLine, prop, ex.Message)
         });
     }
 }
Exemplo n.º 4
0
        protected virtual void OnExecutedPaste()
        {
            OnBeginningEdit(new DataGridBeginningEditEventArgs(Columns.First(), new DataGridRow(), new RoutedEventArgs()));
            var rowData = ClipboardHelper.ParseClipboardData();

            var minColumnDisplayIndex = SelectedCells.Min(x => x.Column.DisplayIndex);
            var maxColumnDisplayIndex = SelectedCells.Max(x => x.Column.DisplayIndex);
            var minRowIndex           = SelectedCells.Min(y => Items.IndexOf(y.Item));
            var maxRowIndex           = SelectedCells.Max(y => Items.IndexOf(y.Item));

            // If single cell select, then use as a starting cell rather than limiting the paste
            if (minColumnDisplayIndex == maxColumnDisplayIndex && minRowIndex == maxRowIndex)
            {
                maxColumnDisplayIndex = Columns.Count - 1;
                maxRowIndex           = Items.Count - 1;
            }

            var rowDataIndex = 0;

            for (var i = minRowIndex; i <= maxRowIndex && rowDataIndex <= rowData.Count() - 1; i++, rowDataIndex++)
            {
                var columnDataIndex = 0;
                for (var j = minColumnDisplayIndex; j <= maxColumnDisplayIndex && columnDataIndex <= rowData[rowDataIndex].Length - 1; j++, columnDataIndex++)
                {
                    var column = ColumnFromDisplayIndex(j);
                    if (column.IsReadOnly)
                    {
                        continue;
                    }
                    column.OnPastingCellClipboardContent(Items[i], rowData[rowDataIndex][columnDataIndex]);
                }
            }
        }
Exemplo n.º 5
0
        protected override void OnSelectedCellsChanged(SelectedCellsChangedEventArgs e)
        {
            foreach (var dataGridCellInfo in e.AddedCells.Where(dataGridCellInfo => (string)dataGridCellInfo.Column.Header == "Timestamp"))
            {
                SelectedCells.Remove(dataGridCellInfo);
            }

            base.OnSelectedCellsChanged(e);
        }
Exemplo n.º 6
0
        public void PasteFromClipboard()
        {
            if (SelectedCells == null || !SelectedCells.Cells().Any())
            {
                throw new ArgumentException("Attempt to paste text into null selection");
            }

            SelectedCells.Cells().First().Value = Clipboard.GetText();
        }
Exemplo n.º 7
0
        public void SetGameDefinition(GameDefinition gameDefinition)
        {
            IsGameOver  = false;
            IsHighScore = false;
            Definition  = gameDefinition;
            SelectedCells.Clear();

            StartTime  = DateTime.Now;
            Grid       = new SquareDataViewModel[Definition.Width, Definition.Height];
            GridStates = new Stack <GridState>();
            Color      = Definition.GameSet.Color;

            for (int x = 0; x < Definition.Width; x++)
            {
                for (int y = 0; y < Definition.Height; y++)
                {
                    Grid[x, y] = new SquareDataViewModel
                    {
                        MarkerVisible = true,
                        //HighColor = Color,
                        //MedColor = "#ADD8E6",
                    };
                }
            }

            int index = 0;

            foreach (var gameLine in Definition.Lines)
            {
                int startX, startY;
                int endX, endY;

                index++;
                //if (string.IsNullOrWhiteSpace(gameLine.Key))
                //    gameLine.Key = index.ToString();

                Definition.GetStartXY(gameLine, out startX, out startY);
                Definition.GetEndXY(gameLine, out endX, out endY);

                var square = Grid[startX, startY];
                square.Fixed        = true;
                square.PaletteIndex = index;
                square.Text         = gameLine.Text;
                square.GameLine     = gameLine;

                square              = Grid[endX, endY];
                square.Fixed        = true;
                square.Text         = gameLine.Text;
                square.PaletteIndex = index;
                square.GameLine     = gameLine;
            }

            Level = string.Format("Level {0}", Definition.Index + 1);

            GetHighScore();
        }
Exemplo n.º 8
0
        public void Paste()
        {
            // parse the clipboard data
            List <string[]> rowData = ClipboardHelper.ParseClipboardData();

            if (rowData != null)
            {
                bool hasAddedNewRow = false;

                // call OnPastingCellClipboardContent for each cell
                int minRowIndex           = Items.IndexOf(CurrentItem);
                int maxRowIndex           = Items.Count - 1;
                int minColumnDisplayIndex = 0;
                int maxColumnDisplayIndex = Columns.Count - 1;
                int rowDataIndex          = 0;
                for (int i = minRowIndex; i <= maxRowIndex && rowDataIndex < rowData.Count; i++, rowDataIndex++)
                {
                    CurrentItem = Items[i];

                    BeginEditCommand.Execute(null, this);

                    int columnDataIndex = 0;
                    for (int j = minColumnDisplayIndex; j <= maxColumnDisplayIndex && columnDataIndex < rowData[rowDataIndex].Length; j++, columnDataIndex++)
                    {
                        DataGridColumn column = ColumnFromDisplayIndex(j);
                        column.OnPastingCellClipboardContent(Items[i], rowData[rowDataIndex][columnDataIndex]);
                    }

                    CommitEditCommand.Execute(this, this);
                    if (i == maxRowIndex)
                    {
                        maxRowIndex++;
                        hasAddedNewRow = true;
                    }
                }

                // update selection
                if (hasAddedNewRow)
                {
                    UnselectAll();
                    UnselectAllCells();

                    CurrentItem = Items[minRowIndex];

                    if (SelectionUnit == DataGridSelectionUnit.FullRow)
                    {
                        SelectedItem = Items[minRowIndex];
                    }
                    else if (SelectionUnit == DataGridSelectionUnit.CellOrRowHeader ||
                             SelectionUnit == DataGridSelectionUnit.Cell)
                    {
                        SelectedCells.Add(new DataGridCellInfo(Items[minRowIndex], Columns[minColumnDisplayIndex]));
                    }
                }
            }
        }
Exemplo n.º 9
0
 public void AddSelectedCell(UltraGridCell cell)
 {
     if (SelectedCells.Where(x => x.RowIndex == cell.RowIndex && x.Key == cell.Key).Count() == 0)
     {
         var cloneCell = Container.Resolve <UltraGridCell>(cell.Row);
         cloneCell.Key      = cell.Key;
         cloneCell.RowIndex = cell.RowIndex;
         SelectedCells.Add(cloneCell);
     }
 }
Exemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        private void CopyTagProperty()
        {
            if (this.SelectedCells.Count() > 0)
            {
                var vt          = SelectedCells.First();
                var tagproperty = (vt.Item as TagViewModel).Clone();

                mPropertyCopy = new Tuple <TagViewModel, int>(tagproperty, vt.Column.DisplayIndex);
            }
        }
Exemplo n.º 11
0
        public IEnumerable <IXLAddress> Find(string value, bool inSelection)
        {
            var result = ActiveSheet.Search(value).AsEnumerable();

            if (inSelection)
            {
                result = result.Where(x => SelectedCells.Contains(x));
            }
            return(result.Select(x => x.Address));
        }
Exemplo n.º 12
0
 protected override void OnSelectedCellsChanged(SelectedCellsChangedEventArgs e)
 {
     if (restoreNextCells && e.RemovedCells.Count > 0)
     {
         foreach (DataGridCellInfo item in e.RemovedCells)
         {
             SelectedCells.Add(item);
         }
         restoreNextCells = false;
     }
     base.OnSelectedCellsChanged(e);
 }
Exemplo n.º 13
0
        /// <summary>
        /// This virtual method is called when ApplicationCommands.Paste command is executed.
        /// </summary>
        /// <param name="args"></param>
        protected virtual void OnExecutedPaste(ExecutedRoutedEventArgs args)
        {
            if (CanClipboardPaste == false)
            {
                return;
            }
            // Parse the clipboard data
            List <string[]> data = ClipboardHelper.ParseClipboardData();

            if (data == null)
            {
                return;
            }

            UnselectAll();
            UnselectAllCells();

            // Call OnPastingCellClipboardContent for each cell
            int minDispRow = Items.IndexOf(CurrentItem);
            int maxDispRow = Items.Count;
            int minDispCol = Columns.IndexOf(CurrentColumn);
            int maxDispCol = Columns.Count;
            int dispRow, dispCol, dataRow, dataCol;

            for (dispRow = minDispRow, dataRow = 0; dataRow < data.Count; dispRow++, dataRow++)
            {
                if (dispRow >= maxDispRow)
                {
                    var itemsSourceList = ItemsSource as IList;
                    var addValue        = Activator.CreateInstance(Items[0].GetType());
                    maxDispRow++;
                    itemsSourceList.Add(addValue);
                }
                BeginEditCommand.Execute(null, this);

                for (dispCol = minDispCol, dataCol = 0; dispCol < maxDispCol && dataCol < data[dataRow].Length; dispCol++, dataCol++)
                {
                    DataGridColumn column = ColumnFromDisplayIndex(dispCol);
                    column.OnPastingCellClipboardContent(Items[dispRow], data[dataRow][dataCol]);

                    if (SelectionUnit == DataGridSelectionUnit.CellOrRowHeader || SelectionUnit == DataGridSelectionUnit.Cell)
                    {
                        SelectedCells.Add(new DataGridCellInfo(Items[dispRow], Columns[dispCol]));
                    }
                }
                if (SelectionUnit == DataGridSelectionUnit.FullRow)
                {
                    SelectedItems.Add(Items[dispRow]);
                }
                CommitEditCommand.Execute(this, this);
            }
        }
Exemplo n.º 14
0
        protected virtual void OnExecutedCopy(ExecutedRoutedEventArgs args)
        {
            // Now find all selected cells and construct the right value (not display value)
            // parse the clipboard data
            List <string[]> rowData = ClipboardHelper.ParseClipboardData();

            // call OnPastingCellClipboardContent for each cell
            int  minRowIndex           = Items.IndexOf(CurrentItem);
            int  maxRowIndex           = Items.Count - 1;
            int  minColumnDisplayIndex = (SelectionUnit != DataGridSelectionUnit.FullRow) ? Columns.IndexOf(CurrentColumn) : 0;
            int  maxColumnDisplayIndex = Columns.Count - 1;
            int  rowDataIndex          = 0;
            bool hasAddedNewRow        = false;

            for (int i = minRowIndex; i <= maxRowIndex && rowDataIndex < rowData.Count; i++, rowDataIndex++)
            {
                if (i == maxRowIndex)
                {
                    maxRowIndex++;
                    hasAddedNewRow = true;
                }
                int columnDataIndex = 0;
                for (int j = minColumnDisplayIndex; j <= maxColumnDisplayIndex && columnDataIndex < rowData[rowDataIndex].Length; j++, columnDataIndex++)
                {
                    DataGridColumn column = ColumnFromDisplayIndex(j);
                    column.OnPastingCellClipboardContent(Items[i], rowData[rowDataIndex][columnDataIndex]);
                }
            }
            if (hasAddedNewRow)
            {
                UnselectAll();
                UnselectAllCells();

                CurrentItem = Items[minRowIndex];
                if (SelectionUnit == DataGridSelectionUnit.FullRow)
                {
                    SelectedItem = Items[minRowIndex];
                }
                else if (SelectionUnit == DataGridSelectionUnit.CellOrRowHeader || SelectionUnit == DataGridSelectionUnit.Cell)
                {
                    SelectedCells.Add(new DataGridCellInfo(Items[minRowIndex], Columns[minColumnDisplayIndex]));
                }
            }
        }
Exemplo n.º 15
0
        public void addTrackInfo(List <Track> tracks)
        {
            IsImporting = true;
            List <int> rows = SelectedCells.Cast <DataGridViewCell>()
                              .Select(x => x.RowIndex).Distinct().ToList <int>();

            bool singleSelected = false;

            if (rows.Count == 0)
            {
                rows.Add(0);                  // start adding from first row if nothing is selected
            }
            if (rows.Count == 1)
            {
                for (int i = 1; i < tracks.Count; i++)
                {
                    if (rows[rows.Count - 1] >= Rows.Count - 1)
                    {
                        break;
                    }
                    rows.Add(rows[rows.Count - 1] + 1);
                }
                singleSelected = true;
            }

            for (int i = 0; i < Math.Min(tracks.Count, rows.Count); i++)
            {
                Track track = tracks[i];
                int   r     = rows[i];

                this[pieceobj.Name, r].Value = track.Piece;
                this[title.Name, r].Value    = track.Name;
            }

            this.Invalidate();
            if (!this.Focused && singleSelected)
            {
                ClearSelection();
                Rows[(rows[rows.Count - 1] + 1 >= Rows.Count ? Rows.Count - 1 : rows[rows.Count - 1] + 1)].Selected = true;
                FirstDisplayedScrollingRowIndex = (SelectedRows[0].Index - DisplayedRowCount(false) / 2 < 0) ?
                                                  0 : SelectedRows[0].Index - DisplayedRowCount(false) / 2;
            }
            IsImporting = false;
        }
Exemplo n.º 16
0
 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
 {
     base.OnPropertyChanged(e);
     if (e.Property == HeaderHeightProperty)
     {
         PositionHeaderCells(ActualWidth);
     }
     if (e.Property == RowHeightProperty)
     {
         PositionRows(ActualWidth);
     }
     if (e.Property == ItemsProperty)
     {
         InvalidateRows();
         PositionRows(ActualWidth);
     }
     if (e.Property == ActualWidthProperty || e.Property == ActualHeightProperty)
     {
         PositionRows(ActualWidth);
         PositionHeaderCells(ActualWidth);
         PositionScroll(ActualWidth);
     }
     if (e.Property == SelectedItemProperty)
     {
         SetSelection(new[] { SelectedItem }, null, null, null);
     }
     if (e.Property == SelectedItemsProperty)
     {
         SetSelection(SelectedItems.ToArray(), null, null, null);
     }
     if (e.Property == SelectedRowsProperty)
     {
         SetSelection(null, SelectedRows.ToArray(), null, null);
     }
     if (e.Property == SelectedColumnsProperty)
     {
         SetSelection(null, null, SelectedColumns.ToArray(), null);
     }
     if (e.Property == SelectedCellsProperty)
     {
         SetSelection(null, null, null, SelectedCells.ToArray());
     }
 }
Exemplo n.º 17
0
        public void CopySelectionToClipboard()
        {
            string textValue = "";

            if (SelectedCells == null)
            {
                return;
            }

            foreach (var row in SelectedCells.Rows())
            {
                if (!string.IsNullOrEmpty(textValue))
                {
                    textValue += "\r\n";
                }
                textValue += string.Join("\t", row.Cells().Select(x => x.Value));
            }
            Clipboard.SetText(textValue);
        }
Exemplo n.º 18
0
        protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            List <DataGridViewCell> selectedCells = null;

            // Intercept left clicks without modifier keys.
            if (AllowMultiRowDrag &&
                (e.Button & MouseButtons.Left) == MouseButtons.Left &&
                ModifierKeys == Keys.None)
            {
                HitTestInfo hitInfo = HitTest(e.X, e.Y);

                // If the empty space is clicked then clean the selection.
                if (hitInfo.Type == DataGridViewHitTestType.None)
                {
                    ClearSelection();
                }
                // If a selected cell is clicked, remember the current selection
                // and temporary suspend the control redrawing.
                else if (hitInfo.Type == DataGridViewHitTestType.Cell &&
                         this[hitInfo.ColumnIndex, hitInfo.RowIndex].Selected)
                {
                    selectedCells      = SelectedCells.OfType <DataGridViewCell>().ToList();
                    holdedCellToSelect = this[hitInfo.ColumnIndex, hitInfo.RowIndex];
                    SendMessage(this.Handle, WM_SETREDRAW, false, 0);
                }
            }

            // Perform base processing.
            base.OnMouseDown(e);

            // Restore selection if necessary and resume the control redrawing.
            if (holdedCellToSelect != null)
            {
                ClearSelection();
                foreach (var cell in selectedCells)
                {
                    cell.Selected = true;
                }
                SendMessage(this.Handle, WM_SETREDRAW, true, 0);
            }
        }
 protected override void OnKeyUp(KeyEventArgs e)
 {
     if ((e.Shift && e.KeyCode == Keys.F10) || e.KeyCode == Keys.Apps)
     {
         // pop context menu on Shift+F10 or context key (i.e. "Apps")
         e.Handled          = true;
         e.SuppressKeyPress = false;
         var selectedCells = SelectedCells.Cast <DataGridViewCell>();
         var cell          = selectedCells.FirstOrDefault(dataGridViewCell => dataGridViewCell.Displayed);
         if (cell != null)
         {
             var rect       = GetCellDisplayRectangle(cell.ColumnIndex, cell.RowIndex, true);
             var bottomLeft = new Point(rect.Left, rect.Bottom);
             InvokeContextMenu(bottomLeft);
         }
     }
     else
     {
         base.OnKeyUp(e);
     }
 }
Exemplo n.º 20
0
        }//end OnPaste

        /// <summary>
        /// Clears the values of the selected cells.
        /// </summary>
        public void OnDelete()
        {
            //Get Selection Range
            ///DataGridViewSelectedCellCollection (selectedCells) doesn't implement a generic
            ///IEnumerable<DataGridViewCell>, just IEnumerable.
            ///To enumerate the values when they are of type 'Object', .Cast<DataGridViewCell>
            var selected = SelectedCells.Cast <DataGridViewCell>().ToList();
            //LINQ method to get start and end indexes
            int startRow = selected.Min(x => x.RowIndex);
            int startCol = selected.Min(x => x.ColumnIndex);
            int endRow   = selected.Max(x => x.RowIndex);
            int endCol   = selected.Max(x => x.ColumnIndex);

            //"Delete" selected cells (by assigning them empty strings)
            for (int irow = startRow; irow < (endRow + 1); irow++)
            {
                for (int jcol = startCol; jcol < (endCol + 1); jcol++)
                {
                    Rows[irow].Cells[jcol].Value = DBNull.Value;
                }
            }
        }
Exemplo n.º 21
0
        void FindRowByStringValue(string searchedValue)
        {
            if (string.IsNullOrWhiteSpace(searchedValue) || CurrentColumn == null)
            {
                return;
            }

            if (CurrentColumn is DataGridTextColumn)
            {
                string searchedText = searchedValue.ToLower();

                var col = CurrentColumn as DataGridTextColumn;

                string bindingPath = (col.Binding as Binding).Path.Path;

                foreach (var item in ItemsSource)
                {
                    // ќпредел¤ем тип источника и получаем искомое свойство
                    var type             = item.GetType();
                    var searchedProperty = type.GetProperty(bindingPath);
                    if (searchedProperty != null)
                    {
                        // ѕредставл¤ем как строку и сравниваем
                        string currentValue = searchedProperty.GetValue(item, null).ToString().ToLower();
                        if (currentValue.StartsWith(searchedText))
                        {
                            var cellInfo = new DataGridCellInfo(item, CurrentColumn);
                            SelectedCells.Clear();
                            SelectedCells.Add(cellInfo);
                            ScrollIntoView(item, CurrentColumn);
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 22
0
        private void ClearSelectedShape()
        {
            if (SelectedLine == null)
            {
                return;
            }

            var allCells = Grid.Flatten().ToList();

            foreach (var square in allCells.Where(s => s.GameLine == SelectedLine))
            {
                square.TouchState    = TouchState.UnTouched;
                square.MarkerVisible = true;

                if (!square.Fixed)
                {
                    square.GameLine = null;
                }

                square.View.Update();
            }
            SelectedLine = null;
            SelectedCells.Clear();
        }
Exemplo n.º 23
0
        public bool TouchStart(SquareDataViewModel cell)
        {
            int x, y;

            FindXY(cell, out x, out y);

            Debug.WriteLine($"TouchStart: {x}, {y}: {cell}");

            if (IsGameOver)
            {
                return(false);
            }
            if (cell?.GameLine == null)
            {
                return(false);
            }

            if (!cell.Fixed)
            {
                return(false);
            }

            if (cell.TouchState == TouchState.Touched)
            {
                SelectedLine = cell.GameLine;
                ClearSelectedShape();

                return(false);
            }

            SelectedLine = cell.GameLine;
            SelectedCells.Add(Definition.GetCellIndex(x, y));
            cell.TouchState = TouchState.Touching;

            return(true);
        }
Exemplo n.º 24
0
        protected override void OnKeyUp(KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Delete:
                foreach (var cell in SelectedCells.Where(x => !x.Column.IsReadOnly))
                {
                    // N.B. Passing in an integer value of zero results in the Gas (MCF) column updating,
                    //      but no other column updating. Using a string "0" results in all values
                    //      updating properly. Very odd behaviour, but insufficient time to investigate why.
                    cell.Column.OnPastingCellClipboardContent(cell.Item, "0");
                }
                OnBeginningEdit(new DataGridBeginningEditEventArgs(Columns.First(), new DataGridRow(), new RoutedEventArgs()));
                break;

            case Key.Enter:
                OnBeginningEdit(new DataGridBeginningEditEventArgs(Columns.First(), new DataGridRow(), new RoutedEventArgs()));
                break;

            default:
                base.OnKeyUp(e);
                break;
            }
        }
 public IStatisticsTableViewModel AddToSelection(int row, int column)
 {
     SelectedCells.Add(Tuple.New(row, column));
     return(this);
 }
 public void ClearSelection()
 {
     SelectedCells.Clear();
 }
Exemplo n.º 27
0
        protected virtual void OnExecutedPaste(ExecutedRoutedEventArgs args)
        {
//            Debug.WriteLine("OnExecutedPaste begin");

            // parse the clipboard data
            List <string[]> rowData = new List <string[]>();// ClipboardHelper.ParseClipboardData();

            string[] color = { "red", "black", "yellow" };
            rowData.Add(color);
            bool hasAddedNewRow = false;

            // call OnPastingCellClipboardContent for each cell
            int minRowIndex           = Items.IndexOf(CurrentItem);
            int maxRowIndex           = Items.Count - 1;
            int minColumnDisplayIndex = (SelectionUnit != DataGridSelectionUnit.FullRow) ? Columns.IndexOf(CurrentColumn) : 0;
            int maxColumnDisplayIndex = Columns.Count - 1;
            int rowDataIndex          = 0;

            for (int i = minRowIndex; i <= maxRowIndex && rowDataIndex < rowData.Count; i++, rowDataIndex++)
            {
                #region 将数据粘贴至新增的行中
                if (CanUserPasteToNewRows && CanUserAddRows && i == maxRowIndex)
                {
                    // add a new row to be pasted to
                    ICollectionView         cv   = CollectionViewSource.GetDefaultView(Items);
                    IEditableCollectionView iecv = cv as IEditableCollectionView;
                    if (iecv != null)
                    {
                        hasAddedNewRow = true;
                        iecv.AddNew();

                        if (rowDataIndex + 1 < rowData.Count)
                        {
                            // still has more items to paste, update the maxRowIndex
                            maxRowIndex = Items.Count - 1;
                        }
                    }
                }
                else if (i == maxRowIndex)
                {
                    continue;
                }
                #endregion

                int columnDataIndex = 0;
                for (int j = minColumnDisplayIndex; j < maxColumnDisplayIndex && columnDataIndex < rowData[rowDataIndex].Length; j++, columnDataIndex++)
                {
                    DataGridColumn column = ColumnFromDisplayIndex(j);
                    column.OnPastingCellClipboardContent(Items[i], rowData[rowDataIndex][columnDataIndex]);
                }
            }
            #region 更新选中区域
            // update selection
            if (hasAddedNewRow)
            {
                UnselectAll();
                UnselectAllCells();

                CurrentItem = Items[minRowIndex];

                if (SelectionUnit == DataGridSelectionUnit.FullRow)
                {
                    SelectedItem = Items[minRowIndex];
                }
                else if (SelectionUnit == DataGridSelectionUnit.CellOrRowHeader ||
                         SelectionUnit == DataGridSelectionUnit.Cell)
                {
                    SelectedCells.Add(new DataGridCellInfo(Items[minRowIndex], Columns[minColumnDisplayIndex]));
                }
            }
            #endregion
        }
Exemplo n.º 28
0
        private void SetSelection(object[] items, LiteRow[] rows, LiteColumn[] columns, UIElement[] cells)
        {
            if (_configuringSelection)
            {
                return;
            }
            _configuringSelection = true;

            items   = items ?? new object[0];
            rows    = rows ?? new LiteRow[0];
            columns = columns ?? new LiteColumn[0];
            cells   = cells ?? new UIElement[0];

            cells = cells
                    .Concat(rows.SelectMany(r => r.Cells))
                    .Concat(columns.SelectMany(c => c.Cells))
                    .Concat(_rows.Where(r => items.Contains(r.Item)).SelectMany(r => r.Cells))
                    .Distinct()
                    .ToArray();
            rows = rows
                   .Concat(cells.Select(LiteRow.GetRow))
                   .Distinct()
                   .ToArray();
            columns = columns
                      .Concat(cells.Select(LiteColumn.GetColumn))
                      .Distinct()
                      .ToArray();

            var selection = new List <DependencyObject>();

            if (SelectionMode.HasFlag(DataGridLiteSelectionMode.SingleCell))
            {
                selection.AddRange(cells.Take(1));
            }
            if (SelectionMode.HasFlag(DataGridLiteSelectionMode.MultiCell))
            {
                selection.AddRange(cells);
            }
            if (SelectionMode.HasFlag(DataGridLiteSelectionMode.SingleRow))
            {
                selection.AddRange(rows.Take(1));
            }
            if (SelectionMode.HasFlag(DataGridLiteSelectionMode.MultiRow))
            {
                selection.AddRange(rows);
            }
            if (SelectionMode.HasFlag(DataGridLiteSelectionMode.SingleColumn))
            {
                selection.AddRange(columns.Take(1));
            }
            if (SelectionMode.HasFlag(DataGridLiteSelectionMode.MultiColumn))
            {
                selection.AddRange(columns);
            }
            selection = selection.Distinct().ToList();

            // Sync all selection types
            SelectedCells   = selection.OfType <UIElement>().Where(s => cells.Contains(s)).ToArray();
            SelectedRows    = selection.OfType <LiteRow>().ToArray();
            SelectedColumns = selection.OfType <LiteColumn>().ToArray();
            SelectedItems   = selection.OfType <LiteRow>()
                              .Concat(SelectedCells.Select(LiteRow.GetRow))
                              .Select(r => r.Item)
                              .ToArray();
            SelectedItem = SelectedItems.FirstOrDefault();

            var selected = selection.Concat(SelectedItems.OfType <DependencyObject>()).ToList();

            selected.ForEach(i => SetIsSelected(i, true));

            var deselected = Items.OfType <DependencyObject>()
                             .Concat(_cells)
                             .Concat(_rows)
                             .Concat(_columns)
                             .Where(i => !selected.Contains(i))
                             .ToList();

            deselected.ForEach(i => SetIsSelected(i, false));

            _configuringSelection = false;
        }
Exemplo n.º 29
0
        /// <summary>
        /// This virtual method is called when ApplicationCommands.Paste command is executed.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="args"></param>
        protected virtual void OnExecutedPaste(object target, ExecutedRoutedEventArgs args)
        {
            if (ExecutePasteEvent != null)
            {
                ExecutePasteEvent(target, args);
                if (args.Handled)
                {
                    return;
                }
            }

            // parse the clipboard data
            List <string[]> rowData = ClipboardHelper.ParseClipboardData();

            bool hasAddedNewRow = false;

            // call OnPastingCellClipboardContent for each cell
            int minRowIndex           = Items.IndexOf(CurrentItem);
            int maxRowIndex           = Items.Count - 1;
            int minColumnDisplayIndex = (SelectionUnit != DataGridSelectionUnit.FullRow) ? Columns.IndexOf(CurrentColumn) : 0;
            int maxColumnDisplayIndex = Columns.Count - 1;
            int rowDataIndex          = 0;

            for (int i = minRowIndex; i <= maxRowIndex && rowDataIndex < rowData.Count; i++, rowDataIndex++)
            {
                if (i < Items.Count)
                {
                    CurrentItem = Items[i];

                    BeginEditCommand.Execute(null, this);

                    int columnDataIndex = 0;
                    for (int j = minColumnDisplayIndex; j <= maxColumnDisplayIndex && columnDataIndex < rowData[rowDataIndex].Length; j++, columnDataIndex++)
                    {
                        DataGridColumn column = ColumnFromDisplayIndex(j);
                        column.OnPastingCellClipboardContent(Items[i], rowData[rowDataIndex][columnDataIndex]);

                        //column.OnPastingCellClipboardContent(
                    }

                    CommitEditCommand.Execute(this, this);
                    if (i == maxRowIndex)
                    {
                        maxRowIndex++;
                        hasAddedNewRow = true;
                    }
                }
            }

            // update selection
            if (hasAddedNewRow)
            {
                UnselectAll();
                UnselectAllCells();

                CurrentItem = Items[minRowIndex];

                if (SelectionUnit == DataGridSelectionUnit.FullRow)
                {
                    SelectedItem = Items[minRowIndex];
                }
                else if (SelectionUnit == DataGridSelectionUnit.CellOrRowHeader ||
                         SelectionUnit == DataGridSelectionUnit.Cell)
                {
                    SelectedCells.Add(new DataGridCellInfo(Items[minRowIndex], Columns[minColumnDisplayIndex]));
                }
            }
        }
Exemplo n.º 30
0
 public void AddToSelectionFrom(int row, int column)
 {
     SelectedCells.Add(Rows[row].Cells[column]);
 }