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])); } } } }
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); } }
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); }
/// <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); } }
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])); } } }
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; } } } } }
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); }
public IStatisticsTableViewModel AddToSelection(int row, int column) { SelectedCells.Add(Tuple.New(row, column)); return(this); }
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 }
public void AddToSelectionFrom(int row, int column) { SelectedCells.Add(Rows[row].Cells[column]); }
/// <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])); } } }
// ****************************************************************** /// <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 [row][column] List <string[]> clipboardData = ClipboardHelper.ParseClipboardData(); bool hasAddedNewRow = false; #if DEBUG StringBuilder sb = new StringBuilder(); #endif int minRowIndex = Items.IndexOf(CurrentItem); int maxRowIndex = Items.Count - 1; int startIndexOfDisplayCol = (SelectionUnit != DataGridSelectionUnit.FullRow) ? CurrentColumn.DisplayIndex : 0; int clipboardRowIndex = 0; for (int i = minRowIndex; i <= maxRowIndex && clipboardRowIndex < clipboardData.Count; i++, clipboardRowIndex++) { if (i < this.Items.Count) { CurrentItem = Items[i]; BeginEditCommand.Execute(null, this); int clipboardColumnIndex = 0; for (int j = startIndexOfDisplayCol; clipboardColumnIndex < clipboardData[clipboardRowIndex].Length; j++, clipboardColumnIndex++) { // DataGridColumn column = ColumnFromDisplayIndex(j); DataGridColumn column = null; foreach (DataGridColumn columnIter in this.Columns) { if (columnIter.DisplayIndex == j) { column = columnIter; break; } } column?.OnPastingCellClipboardContent(Items[i], clipboardData[clipboardRowIndex][clipboardColumnIndex]); #if DEBUG sb.AppendFormat("{0,-10}", clipboardData[clipboardRowIndex][clipboardColumnIndex]); sb.Append(" - "); #endif } CommitEditCommand.Execute(this, this); if (i == maxRowIndex) { maxRowIndex++; hasAddedNewRow = true; } } #if DEBUG sb.Clear(); #endif } // 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[startIndexOfDisplayCol])); } } }
public bool TouchCell(SquareDataViewModel cell) { if (cell == null) { return(false); } int x, y; FindXY(cell, out x, out y); int cellIndex = Definition.GetCellIndex(x, y); int lastCellIndex = SelectedCells.Count == 0 ? -1 : SelectedCells.Last(); Debug.WriteLine($"TouchCell: {x}, {y}: {cell}"); if (IsGameOver) { return(false); } if (SelectedLine == null) { return(false); } if (lastCellIndex == cellIndex) { return(false); // Ain't moved } if (cell.TouchState == TouchState.Touched) { return(false); } // Touching another line start/end if (cell.Fixed && cell.GameLine != SelectedLine) { return(false); } // If selected cell is already in the list. This is when the user goes backwards if (SelectedCells.Contains(cellIndex)) { // The user has back tracked var index = SelectedCells.LastIndexOf(cellIndex); while (SelectedCells.Count > index) { var last = SelectedCells.Last(); SelectedCells.RemoveAt(SelectedCells.Count() - 1); int lastX, lastY; Definition.GetCellXY(last, out lastX, out lastY); var lastCell = Grid[lastX, lastY]; lastCell.TouchState = TouchState.UnTouched; } if (index < SelectedCells.Count) { SelectedCells.RemoveRange(index + 1, SelectedCells.Count - index); } return(true); } if (lastCellIndex >= 0) { if (!AreCellsNextToEachOther(lastCellIndex, cellIndex)) { return(false); } } cell.TouchState = TouchState.Touching; cell.GameLine = SelectedLine; SelectedCells.Add(cellIndex); return(true); }