Example #1
0
        /// <summary>
        /// Handles selection when any of the <see cref="Syncfusion.UI.Xaml.Grid.PointerOperation"/> such as pressed,released,moved,and etc performed in SfTreeGrid.
        /// </summary>
        /// <param name="args">
        /// The <see cref="Syncfusion.UI.Xaml.Grid.GridPointerEventArgs"/> that contains the type of pointer operations and its arguments.
        /// </param>
        /// <param name="rowColumnIndex">
        /// The corresponding rowColumnIndex of the cell.
        /// </param>
        /// <remarks>
        /// This method is invoked when any of the <see cref="Syncfusion.UI.Xaml.Grid.PointerOperation"/> are performed in SfTreeGrid.
        /// </remarks>
        public virtual void HandlePointerOperations(GridPointerEventArgs args, RowColumnIndex rowColumnIndex)
        {
            switch (args.Operation)
            {
            case PointerOperation.Pressed:
                this.ProcessPointerPressed(args.OriginalEventArgs as MouseButtonEventArgs, rowColumnIndex);
                break;

            case PointerOperation.Released:
                this.ProcessPointerReleased(args.OriginalEventArgs as MouseButtonEventArgs, rowColumnIndex);
                break;

            case PointerOperation.Move:
                ProcessPointerMoved(args.OriginalEventArgs as MouseEventArgs, rowColumnIndex);
                break;

            case PointerOperation.Tapped:
                this.ProcessOnTapped(args.OriginalEventArgs as TappedEventArgs, rowColumnIndex);
                break;

            case PointerOperation.DoubleTapped:
                this.ProcessOnDoubleTapped(rowColumnIndex);
                break;

#if WPF
            case PointerOperation.Wheel:
                this.ProcessPointerWheel(args.OriginalEventArgs as MouseWheelEventArgs, rowColumnIndex);
                break;
#endif
            }
        }
        public override void OnInitializeEditElement(DataColumnBase dataColumn, GridDetailsViewExpanderCell uiElement, object dataContext)
        {
            RowColumnIndex rowColumnIndex = new RowColumnIndex(dataColumn.RowIndex, dataColumn.ColumnIndex);

            uiElement.DataGrid       = DataGrid;
            uiElement.RowColumnIndex = rowColumnIndex;
        }
 public void SetCurrentCellState(RowColumnIndex currentCellIndex, FrameworkElement currentCellElement, bool isInEditing, bool isFocused, TreeGridColumn column, TreeDataColumnBase dc)
 {
     hasCurrentCellState   = true;
     this.currentCellIndex = currentCellIndex;
     if (UseOnlyRendererElement)
     {
         this.currentCellElement    = null;
         currentCellRendererElement = currentCellElement;
     }
     else
     {
         this.currentCellElement = currentCellElement;
         if (currentCellElement is TreeGridCell)
         {
             if (column.hasCellTemplate || column.hasCellTemplateSelector)
             {
                 currentCellRendererElement = currentCellElement as FrameworkElement;
             }
             else
             {
                 currentCellRendererElement = (currentCellElement as TreeGridCell).Content as FrameworkElement;
             }
         }
     }
     IsInEditing = isInEditing;
     if (isFocused)
     {
         this.SetFocus(this.IsFocusable);
     }
 }
Example #4
0
        private void CheckBoxSelection(RowColumnIndex rowcolumnIndex)
        {
            var selectedrow = this.SelectedRows.FindAll(item => item.RowIndex == rowcolumnIndex.RowIndex);

            if (selectedrow.Count == 0)
            {
                var row = this.DataGrid.GetRecordAtRowIndex(rowcolumnIndex.RowIndex);
                (row as OrderInfo).IsSelected = false;
            }
            else
            {
                (selectedrow[0].RowData as OrderInfo).IsSelected = true;
            }
            var collectioncount   = (DataGrid.DataContext as ViewModel).OrderInfoCollection.Count;
            var selecteditemcount = DataGrid.SelectedItems.Count;

            if (selecteditemcount == collectioncount)
            {
                (this.DataGrid.DataContext as ViewModel).IsSelectAll = true;
            }
            else if (selecteditemcount == 0)
            {
                (this.DataGrid.DataContext as ViewModel).IsSelectAll = false;
            }
            else
            {
                (this.DataGrid.DataContext as ViewModel).IsSelectAll = null;
            }
        }
        /// <summary>
        /// Occurs when the input system reports an underlying dragover event with this element as the potential drop target.
        /// </summary>
        /// <param name="args">An <see cref="T:Windows.UI.Xaml.DragEventArgs">DragEventArgs</see> that contains the event data.</param>
        /// <param name="rowColumnIndex">Specifies the row column index based on the mouse point.</param>
        protected override void ProcessOnDragOver(DragEventArgs args, RowColumnIndex rowColumnIndex)
        {
            if (args.Data.GetDataPresent("ListViewRecords"))
            {
                draggingRecords = args.Data.GetData("ListViewRecords") as ObservableCollection <object>;
            }
            else
            {
                draggingRecords = args.Data.GetData("Records") as ObservableCollection <object>;
            }

            if (draggingRecords == null)
            {
                return;
            }

            //To get the dropping position of the record
            var dropPosition = GetDropPosition(args, rowColumnIndex, draggingRecords);

            //To Show the draggable popup with the DropAbove/DropBelow message
            ShowDragDropPopup(dropPosition, draggingRecords, args);
            //To Show the up and down indicators while dragging the row
            ShowDragIndicators(dropPosition, rowColumnIndex, args);

            args.Handled = true;
        }
Example #6
0
        protected override void InitializeCellStyle(TreeDataColumnBase treeDataColumn, object record)
        {
            var cell               = treeDataColumn.ColumnElement;
            var column             = treeDataColumn.TreeGridColumn;
            var cellRowColumnIndex = new RowColumnIndex(treeDataColumn.RowIndex, treeDataColumn.ColumnIndex);

            var control = cell as TreeGridHeaderCell;

            if (control != null && TreeGrid != null && column != null)
            {
                if (this.TreeGrid.AllowResizingColumns && this.TreeGrid.AllowResizingHiddenColumns)
                {
                    var columnIndex = this.TreeGrid.ResolveToGridVisibleColumnIndex(cellRowColumnIndex.ColumnIndex);
                    this.TreeGrid.ColumnResizingController.EnsureVSMOnColumnCollectionChanged(-1, columnIndex);
                }
                // UWP-4721 Reset the style while resuing a column with HeaderStyle for GridHeaderCellControl.
                if (!column.hasHeaderStyle && !TreeGrid.hasHeaderStyle)
                {
                    if (control.ReadLocalValue(GridHeaderCellControl.StyleProperty) != DependencyProperty.UnsetValue)
                    {
                        control.ClearValue(GridHeaderCellControl.StyleProperty);
                    }
                }
                else
                {
                    Style style = null;
                    if (column.hasHeaderStyle)
                    {
                        style = column.HeaderStyle;
                    }
                    else if (TreeGrid.hasHeaderStyle)
                    {
                        style = TreeGrid.HeaderStyle;
                    }
                    // WPF-35780 - When the Headerstyle is explicitly set null value for a column whether TreeGrid Headerstyle is enabled,
                    // we need to clear the style for the column.
                    if (style != null)
                    {
                        control.Style = style;
                    }
                    else
                    {
                        control.ClearValue(GridHeaderCellControl.StyleProperty);
                    }
                }

                if (!column.hasHeaderTemplate && !TreeGrid.hasHeaderTemplate)
                {
                    control.ClearValue(GridHeaderCellControl.ContentTemplateProperty);
                }
                else if (column.hasHeaderTemplate)
                {
                    control.ContentTemplate = column.HeaderTemplate;
                }
                else if (TreeGrid.hasHeaderTemplate)
                {
                    control.ContentTemplate = TreeGrid.HeaderTemplate;
                }
            }
        }
Example #7
0
        protected override void OnTextInput(TextCompositionEventArgs e)
        {
            if (!SelectionController.CurrentCellManager.HasCurrentCell)
            {
                base.OnTextInput(e);
                return;
            }

            //Get the Current Row and Column index from the CurrentCellManager
            RowColumnIndex rowColumnIndex = SelectionController.CurrentCellManager.CurrentRowColumnIndex;

            if (e.OriginalSource is SfDataGridExt dataGrid)
            {
                RowGenerator          rowGenerator  = dataGrid.RowGenerator;
                DataRowBase           dataRow       = rowGenerator.Items.FirstOrDefault(item => item.RowIndex == rowColumnIndex.RowIndex);
                List <DataColumnBase> visiblecolumn = dataRow?.VisibleColumns;
                if (dataRow is DataRow)
                {
                    //Get the column from the VisibleColumn collection based on the column index
                    DataColumnBase dataColumn = visiblecolumn.FirstOrDefault(column => column.ColumnIndex == rowColumnIndex.ColumnIndex);
                    //Convert the input text to char type
                    char.TryParse(e.Text, out char text);
                    //Skip if the column is GridTemplateColumn and the column is not already in editing
                    //Allow Editing only pressed letters digits and Minus sign key
                    if (dataColumn != null && !dataColumn.IsEditing &&
                        SelectionController.CurrentCellManager.BeginEdit() &&
                        char.IsLetterOrDigit(text) || char.IsPunctuation(text))
                    {
                        dataColumn?.Renderer.PreviewTextInput(e);
                    }
                }
            }

            base.OnTextInput(e);
        }
Example #8
0
        /// <summary>
        /// Method which is initialize the Renderer element Bindings with corresponding column values.
        /// </summary>
        /// <param name="dataColumn">DataColumn Which holds GridColumn, RowColumnIndex and GridCell </param>
        /// RowColumnIndex - RowColumnIndex for the Renderer Elements
        /// <param name="uiElement">Corresponding Renderer Element</param>
        /// GridColumn - Column which is providing the information for Binding
        /// <param name="dataContext"></param>
        /// <remarks></remarks>
        public override void OnInitializeEditElement(DataColumnBase dataColumn, CheckBox uiElement, object dataContext)
        {
            RowColumnIndex rowColumnIndex = new RowColumnIndex(dataColumn.RowIndex, dataColumn.ColumnIndex);
            GridColumn     column         = dataColumn.GridColumn;

#if WPF
            uiElement.FocusVisualStyle = null;
#else
            uiElement.UseSystemFocusVisuals = false;
#endif
            var binding = new Binding {
                Path = new PropertyPath("FilterRowText"), Mode = BindingMode.TwoWay, Source = column
            };
            uiElement.SetBinding(CheckBox.IsCheckedProperty, binding);
            uiElement.IsThreeState = true;
            var paddingBind = new Binding {
                Path = new PropertyPath("Padding"), Mode = BindingMode.TwoWay, Source = column
            };
            uiElement.SetBinding(Control.PaddingProperty, paddingBind);
            var hAlignBind = new Binding {
                Path = new PropertyPath("HorizontalAlignment"), Mode = BindingMode.TwoWay, Source = column
            };
            uiElement.SetBinding(FrameworkElement.HorizontalAlignmentProperty, hAlignBind);
            var vAlignBind = new Binding {
                Path = new PropertyPath("VerticalAlignment"), Mode = BindingMode.TwoWay, Source = column
            };
            uiElement.SetBinding(FrameworkElement.VerticalAlignmentProperty, vAlignBind);
#if UWP
            uiElement.MinWidth  = 0;
            uiElement.MinHeight = 0;
#endif
            uiElement.Tag = rowColumnIndex;
        }
        private void OnMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton != MouseButton.Left)
            {
                return;
            }


            if (HasCurrentCellState && !((CheckBox)sender).IsPressed && IsFocused)
            {
                ((CheckBox)sender).IsChecked = !((CheckBox)sender).IsChecked;

                TreeGridCell treeGridCell = null;

                var checkBox = sender as CheckBox;

                if (checkBox.Parent is TreeGridCell)
                {
                    treeGridCell = checkBox.Parent as TreeGridCell;
                }

                var rowColumnIndex = new RowColumnIndex();
                rowColumnIndex.RowIndex    = treeGridCell != null ? treeGridCell.ColumnBase.RowIndex : new RowColumnIndex().RowIndex;
                rowColumnIndex.ColumnIndex = treeGridCell != null ? treeGridCell.ColumnBase.ColumnIndex : new RowColumnIndex().ColumnIndex;

                if (!rowColumnIndex.IsEmpty)
                {
                    TreeGrid.RaiseCurrentCellValueChangedEvent(new TreeGridCurrentCellValueChangedEventArgs(TreeGrid)
                    {
                        RowColumnIndex = rowColumnIndex, Record = checkBox.DataContext, Column = treeGridCell.ColumnBase.TreeGridColumn
                    });
                }
            }
        }
Example #10
0
        void grid_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            GridControl gridControl = sender as GridControl;

            if (gridControl.CurrentCell.IsEditing)
            {
                gridControl.CurrentCell.Deactivate();
            }
            RowColumnIndex cell = grid.PointToCellRowColumnIndex(e.GetPosition(grid));

            if (cell.RowIndex == 0 && cell.ColumnIndex > 0)
            {
                if (cell.ColumnIndex == sortedColumn)
                {
                    sortDirection = sortDirection == ListSortDirection.Ascending ? ListSortDirection.Descending : ListSortDirection.Ascending;
                }
                else
                {
                    sortDirection = ListSortDirection.Ascending;
                }
                sortedColumn = cell.ColumnIndex;
                gridControl.SortColumn(sortedColumn, sortDirection);
                e.Handled = true;
            }
        }
Example #11
0
        /// <summary>
        /// Occurs when the input system reports an underlying drop event with this element as the drop target.
        /// </summary>
        /// <param name="args">An <see cref="T:Windows.UI.Xaml.DragEventArgs">DragEventArgs</see> that contains the event data.</param>
        /// <param name="rowColumnIndex">Specifies the row column index based on the mouse point.</param>
        internal protected virtual void ProcessOnDrop(DragEventArgs args, RowColumnIndex rowColumnIndex)
        {
            StopTimer();
            autoExpandNode = null;
            if (!TreeGrid.SelectionController.CurrentCellManager.CheckValidationAndEndEdit())
            {
                return;
            }
            this.TreeGrid.AutoScroller.AutoScrolling = AutoScrollOrientation.None;
            var dropPosition = GetDropPosition(args, rowColumnIndex);

            if (dropPosition != DropPosition.None && rowColumnIndex.RowIndex != -1)
            {
                var nodes          = GetNodes(args);
                var sourceTreeGrid = GetSourceTreeGrid(args);
                if (this.TreeGrid.View is TreeGridNestedView)
                {
                    ProcessDropOnNestedView(rowColumnIndex, dropPosition, nodes, sourceTreeGrid);
                }
                else if (this.TreeGrid.View is TreeGridUnboundView)
                {
                    ProcessDropOnUnboundView(rowColumnIndex, dropPosition, nodes, sourceTreeGrid);
                }
                else if (this.TreeGrid.View is TreeGridSelfRelationalView)
                {
                    ProcessDropOnSelfRelationalView(rowColumnIndex, dropPosition, nodes, sourceTreeGrid);
                }
            }
            CloseDragIndicators();
        }
Example #12
0
        private void Clear_Click(object sender, RoutedEventArgs e)
        {
            GridRangeInfo Range = cellGrid.SelectedRanges.ActiveRange;

            if (Range.IsTable)
            {
                cellGrid.Model.ClearStyles();
                cellGrid.InvalidateCells();
            }
            else
            {
                if (Range.IsRows)
                {
                    Range = GridRangeInfo.Cells(Range.Top, cellGrid.HeaderColumns, Range.Bottom, cellGrid.ColumnCount);
                }
                else if (Range.IsCols)
                {
                    Range = GridRangeInfo.Cells(cellGrid.HeaderRows, Range.Left, cellGrid.RowCount, Range.Right);
                }

                for (int i = Range.Top; i <= Range.Bottom; i++)
                {
                    for (int j = Range.Left; j <= Range.Right; j++)
                    {
                        RowColumnIndex rowcol = new RowColumnIndex(i, j);
                        cellGrid.Model.ClearStyle(rowcol);
                    }
                }
                cellGrid.InvalidateCell(Range);
            }
            cellGrid.ShowHidePopup(false);
        }
 protected override void ProcessPointerReleased(MouseButtonEventArgs args, RowColumnIndex rowColumnIndex)
 {
     base.ProcessPointerReleased(args, rowColumnIndex);
     CheckBoxSelection(rowColumnIndex);
     args.Handled = true;
     this.TreeGrid.Focus();
 }
        private void CheckBoxSelection(RowColumnIndex rowcolumnIndex)
        {
            var selectedrow = this.SelectedRows.FindAll(item => item.RowIndex == rowcolumnIndex.RowIndex);

            if (selectedrow.Count == 0)
            {
                var row = this.TreeGrid.GetNodeAtRowIndex(rowcolumnIndex.RowIndex).Item;
                (row as EmployeeInfo).IsSelected = false;
            }
            else
            {
                (selectedrow[0].RowData as EmployeeInfo).IsSelected = true;
            }
            var collectioncount   = (this.TreeGrid.DataContext as ViewModel).EmployeeInfo.Count;
            var selecteditemcount = this.TreeGrid.SelectedItems.Count;

            if (selecteditemcount == collectioncount)
            {
                (this.TreeGrid.DataContext as ViewModel).IsSelectAll = true;
            }
            else if (selecteditemcount == 0)
            {
                (this.TreeGrid.DataContext as ViewModel).IsSelectAll = false;
            }
            else
            {
                (this.TreeGrid.DataContext as ViewModel).IsSelectAll = null;
            }
        }
        private void SfDataGrid_CurrentCellActivated(object sender, Syncfusion.WinForms.DataGrid.Events.CurrentCellActivatedEventArgs e)
        {
            RowColumnIndex rowColumnIndex = new RowColumnIndex(e.DataRow.Index, e.DataColumn.Index);

            sfDataGrid.MoveToCurrentCell(rowColumnIndex);
            this.sfDataGrid.CurrentCell.BeginEdit();
        }
Example #16
0
        /// <summary>
        /// Updates the binding of the Cell UIElement for the specified column.
        /// Implement this method to update binding when the cell UIElement is reused during horizontal scrolling.
        /// </summary>
        /// <param name="dataColumn">
        /// Specifies the corresponding column to update binding.
        /// </param>
        /// <param name="record">
        /// The corresponding record to update binding.
        /// </param>
        /// <param name="isInEdit">
        /// Indicates the whether the cell is editable or not.
        /// </param>
        protected internal override void OnUpdateBindingInfo(TreeDataColumnBase dataColumn, object record, bool isInEdit)
        {
            RowColumnIndex   cellRowColumnIndex = new RowColumnIndex(dataColumn.RowIndex, dataColumn.ColumnIndex);
            FrameworkElement uiElement          = dataColumn.ColumnElement;
            TreeGridColumn   column             = dataColumn.TreeGridColumn;
            FrameworkElement rendererElement    = null;

            if (UseOnlyRendererElement)
            {
                rendererElement = uiElement as FrameworkElement;
            }
            else if (uiElement is TreeGridCell)
            {
                rendererElement = (uiElement as TreeGridCell).Content is FrameworkElement ? (uiElement as TreeGridCell).Content as FrameworkElement : uiElement;
            }

            if (this.SupportsRenderOptimization && !isInEdit)
            {
                if (!column.hasCellTemplate && !column.hasCellTemplateSelector)
                {
                    OnUpdateDisplayBinding(dataColumn, (D)rendererElement, record);
                }
                else
                {
                    OnUpdateTemplateBinding(dataColumn, (ContentControl)rendererElement, record);
                }
            }
            else
            {
                OnUpdateEditBinding(dataColumn, (E)rendererElement, record);
            }
        }
Example #17
0
 /// <summary>
 /// Initialize a new object.
 /// </summary>
 /// <param name="rowIndex">The row index.</param>
 /// <param name="colIndex">The column index.</param>
 /// <param name="range">A <see cref="CoveredCellInfo"/> that will receive the resulting range for the covered cell.</param>
 public GridQueryCoveredRangeEventArgs(RowColumnIndex cellRowColumnIndex, CoveredCellInfo range, GridColumn column, object record, object originalSource) : base(originalSource)
 {
     this.range = range;
     this.cellRowColumnIndex = cellRowColumnIndex;
     this.column             = column;
     this.record             = record;
 }
        public int HitTest(MouseControllerEventArgs mouseEventArgs, IMouseController controller)
        {
            Point point = mouseEventArgs.Location;

            GridRangeInfo range = Grid.Model.SelectedCells;

            if (range == null || range.IsEmpty)
            {
                return(0);
            }

            RowColumnIndex  pos    = Grid.PointToCellRowColumnIndex(point, true);
            VisibleLineInfo hitRow = HitRowTest(point);

            if (hitRow != null && !this.IsNotNested(hitRow) && range.Bottom == hitRow.LineIndex)
            {
                VisibleLineInfo column = HitColTest(point);//Grid.ScrollColumns.GetVisibleLineAtPoint(point.X);

                if (column != null && range.Right == column.LineIndex)
                {
                    //  Grid.InvalidateCells();
                    return(1);
                }
            }
            return(0);
        }
Example #19
0
        protected override void OnInitializeEditElement(DataColumnBase column, RowColumnIndex rowColumnIndex, SfNumericTextBox uiElement)
        {
            base.OnInitializeEditElement(column, rowColumnIndex, uiElement);
            uiElement.TextChanged += UiElement_TextChanged;

            this.RowColumnIndex = rowColumnIndex;
        }
Example #20
0
        protected override void ProcessOnDragOver(DragEventArgs args, RowColumnIndex rowColumnIndex)
        {
            autoExpandNode = null;
            var node         = this.TreeGrid.GetNodeAtRowIndex(rowColumnIndex.RowIndex);
            var draggedItem  = GetDraggedItem(args);
            var dropPosition = GetDropPosition(args, rowColumnIndex);

            if (draggedItem == null)
            {
                return;
            }

            if (dropPosition == DropPosition.None || dropPosition == DropPosition.Default)
            {
                CloseDragIndicators();
                args.AcceptedOperation      = DataPackageOperation.None;
                args.DragUIOverride.Caption = "Can't drop here";
                return;
            }
            else if (dropPosition == DropPosition.DropAbove)
            {
                args.DragUIOverride.Caption = "Drop above";
            }
            else if (dropPosition == DropPosition.DropAsChild)
            {
                args.DragUIOverride.Caption = "Drop as child";
            }
            else
            {
                args.DragUIOverride.Caption = "Drop below";
            }
            args.AcceptedOperation = DataPackageOperation.Move;
            ShowDragIndicators(dropPosition, rowColumnIndex);
            args.Handled = true;
        }
        /// <summary>
        /// Processes the selection when the mouse point is double tapped on the particular cell in SfTreeGrid.
        /// </summary>
        /// <param name="currentRowColumnIndex">
        /// The corresponding rowColumnIndex of the mouse point.
        /// </param>
        /// <remarks>
        /// This method invoked to process selection and begin edit the cell when <see cref="Syncfusion.UI.Xaml.Grid.EditTrigger"/> is <see cref="Syncfusion.UI.Xaml.Grid.EditTrigger.OnDoubleTap"/>.
        /// </remarks>
        protected override void ProcessOnDoubleTapped(RowColumnIndex currentRowColumnIndex)
        {
            if (IsSuspended || this.TreeGrid.SelectionMode == GridSelectionMode.None || this.CurrentCellManager.CurrentRowColumnIndex != currentRowColumnIndex || this.TreeGrid.NavigationMode == NavigationMode.Row)
            {
                return;
            }

            if (this.TreeGrid.EditTrigger == EditTrigger.OnDoubleTap)
            {
                if (this.TreeGrid.SelectionMode != GridSelectionMode.Single)
                {
                    if (!SelectedRows.Any(r => r.RowIndex == currentRowColumnIndex.RowIndex))
                    {
                        var rowInfo = GetTreeGridSelectedRow(currentRowColumnIndex.RowIndex);
                        this.AddSelection(new List <object>()
                        {
                            rowInfo
                        });
                        if (TreeGrid.EnableRecursiveChecking)
                        {
                            SelectRowsOnRecursiveCheck(rowInfo.Node, needToRemoveItems: false);
                        }
                    }
                }
                CurrentCellManager.ProcessOnDoubleTapped();
            }
        }
Example #22
0
        /// <summary>
        /// Called when [CheckBox click].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        void OnCheckBoxClick(object sender, RoutedEventArgs e)
        {
            var checkBox = sender as CheckBox;

#if !WPF
            GridCell gridCell = null;
            if (checkBox.Parent is GridCell)
            {
                gridCell = checkBox.Parent as GridCell;
            }
            RowColumnIndex rowcolumnIndex = new RowColumnIndex();
            rowcolumnIndex.RowIndex    = gridCell != null ? gridCell.ColumnBase.RowIndex : new RowColumnIndex().RowIndex;
            rowcolumnIndex.ColumnIndex = gridCell != null ? gridCell.ColumnBase.ColumnIndex : new RowColumnIndex().ColumnIndex;

            if (!rowcolumnIndex.IsEmpty)
            {
                this.DataGrid.SelectionController.HandlePointerOperations(new GridPointerEventArgs(PointerOperation.Pressed, null), rowcolumnIndex);
                this.DataGrid.SelectionController.HandlePointerOperations(new GridPointerEventArgs(PointerOperation.Released, null), rowcolumnIndex);
            }
#endif
            if (HasCurrentCellState)
            {
                this.IsValueChanged = true;
                this.ProcessSingleFilter(GetControlValue());
#if !WPF
                checkBox.Focus(FocusState.Programmatic);
#else
                checkBox.Focus();
#endif
            }
        }
        public virtual void MouseUp(MouseControllerEventArgs e)
        {
            Internalmovdir = MoveDir;
            BackUpCellValues.Clear();
            CellData = new GridCellData();

            for (int Row = Gridmodel.SelectedCells.Top; Row <= Gridmodel.SelectedCells.Bottom; Row++)
            {
                for (int Column = this.SelectedRange.Left; Column <= this.SelectedRange.Right; Column++)
                {
                    var CellRowColumnIndex            = new RowColumnIndex(Row, Column);
                    GridStyleInfoStore styleinfostore = (GridStyleInfoStore)this.grid.Model[Row, Column].Store.Clone();
                    //this.CellData[this.grid.Model[Row, Column].CellRowColumnIndex] = styleinfostore;
                    BackUpCellValues.Add(CellRowColumnIndex, styleinfostore);//this.CellData[this.grid.Model[Row, Column].CellRowColumnIndex]);
                }
            }
            this.InnerFillType = SeriesType.FillSeries;
            this.FillData();

            MoveDir     = MovingDirection.None;
            IsMouseDown = false;

#if !SILVERLIGHT
            if (Buttonside == MouseButton.Left)
#else
            if (Buttonside == MouseButtons.Left)
#endif
            {
                OpenFilterDropDown();
            }
        }
        public virtual int HitTest(MouseControllerEventArgs mouseEventArgs, IMouseController controller)
        {
            Point point = mouseEventArgs.Location;

            GridRangeInfo range = grid.Model.SelectedCells;

            if (range == null || range.IsEmpty)
            {
                return(0);
            }

            RowColumnIndex pos = grid.PointToCellRowColumnIndex(point, true);

            if (pos != RowColumnIndex.Empty && MoveDir != MovingDirection.None)
            {
                return(1);
            }

            VisibleLineInfo hitRow = HitRowTest(point);

            if (hitRow != null && !this.IsNotNested(hitRow) && range.Bottom == hitRow.LineIndex)
            {
                VisibleLineInfo column = HitColTest(point);
                if (column != null && range.Right == column.LineIndex)
                {
                    return(1);
                }
            }

            return(0);
        }
Example #25
0
        /// <summary>
        /// Sets drag indicators in appropriate position.
        /// </summary>
        /// <param name="dropPosition">
        /// Indicates the drop position, based on that the indicators will shown.
        /// </param>
        /// <param name="rowColumnIndex">
        /// Specifies the rowColumn index based on mouse hover.
        /// </param>
        protected virtual void ShowDragIndicators(DropPosition dropPosition, RowColumnIndex rowColumnIndex)
        {
            if (upArrowIndicator == null && downArrowIndicator == null)
            {
                upArrowIndicator         = new Popup();
                downArrowIndicator       = new Popup();
                upArrowIndicator.Child   = new UpIndicatorContentControl();
                downArrowIndicator.Child = new DownIndicatorContentControl();
            }
            var lineinfo = TreeGrid.TreeGridPanel.ScrollRows.GetVisibleLineAtLineIndex(rowColumnIndex.RowIndex);

            var upHoffset   = 0.0;
            var downHoffset = 0.0;
            var upVoffset   = 0.0;
            var downVoffset = 0.0;

            double width = 0;

            if (TreeGrid.showRowHeader)
            {
                width = this.TreeGrid.RowHeaderWidth / 2;
            }
            else
            {
                width = 22;
            }
            upHoffset = downHoffset = this.TreeGrid.GetControlRect(this.TreeGrid).X + width;

            if (dropPosition == DropPosition.DropAbove)
            {
                CloseDragIndicators();
                upVoffset   = lineinfo.Origin + 5;
                downVoffset = lineinfo.Origin - (22);
                //VisualStateManager.GoToState(GetRowControl(rowColumnIndex), "DropAbove", true);
            }
            else if (dropPosition == DropPosition.DropBelow)
            {
                CloseDragIndicators();
                upVoffset   = lineinfo.Corner + 5;
                downVoffset = lineinfo.Corner - 22;
                //VisualStateManager.GoToState(GetRowControl(rowColumnIndex), "DropBelow", true);
            }
            else
            {
                CloseDragIndicators();
                //VisualStateManager.GoToState(GetRowControl(rowColumnIndex), "DropOver", true);
                return;
            }

            // Need to convert the values to their related screen coordinates
            upArrowIndicator.IsOpen   = true;
            downArrowIndicator.IsOpen = true;
            var pt1 = this.TreeGrid.TransformToVisual(null).TransformPoint(new Point(upHoffset, upVoffset));
            var pt2 = this.TreeGrid.TransformToVisual(null).TransformPoint(new Point(downHoffset, downVoffset));

            upArrowIndicator.HorizontalOffset   = pt1.X;
            downArrowIndicator.HorizontalOffset = pt2.X;
            upArrowIndicator.VerticalOffset     = pt1.Y;
            downArrowIndicator.VerticalOffset   = pt2.Y;
        }
Example #26
0
        /// <summary>
        /// To find the first/last error cell in view if selection is not maintained in datagrid.
        /// </summary>
        private void MoveToErrorCell(SfDataGrid datagrid, bool MoveToFirstCell, ref bool moveToRow)
        {
            RowColumnIndex rowColumnIndex;

            if (MoveToFirstCell)
            {
                rowColumnIndex = new RowColumnIndex(datagrid.GetFirstDataRowIndex(), datagrid.GetFirstColumnIndex());
            }
            else
            {
                rowColumnIndex = new RowColumnIndex(datagrid.GetLastDataRowIndex(), datagrid.GetLastColumnIndex());
            }

            datagrid.SelectionController.MoveCurrentCell(rowColumnIndex);
            var currentRowColumnIndex = datagrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex;
            var gridCellCollections   = GetGridCellCollection(datagrid, currentRowColumnIndex);

            if (gridCellCollections != null)
            {
                foreach (var gridCellItem in gridCellCollections)
                {
                    var gridCell = gridCellItem as GridCell;
                    if (gridCell != null && gridCell.HasError && gridCell.ColumnBase.ColumnIndex == currentRowColumnIndex.ColumnIndex)
                    {
                        datagrid.SelectionController.MoveCurrentCell(new RowColumnIndex(currentRowColumnIndex.RowIndex, gridCell.ColumnBase.ColumnIndex));
                        datagrid.ScrollInView(datagrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex);;
                        moveToRow = false;
                        return;
                    }
                }
            }
        }
        /// <summary>
        /// Called when [CheckBox click].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        void OnCheckBoxClick(object sender, RoutedEventArgs e)
        {
            var checkBox = sender as CheckBox;

            TreeGridCell treeGridCell = null;

            if (checkBox.Parent is TreeGridCell)
            {
                treeGridCell = checkBox.Parent as TreeGridCell;
            }


            var rowcolumnIndex = new RowColumnIndex();

            rowcolumnIndex.RowIndex    = treeGridCell != null ? treeGridCell.ColumnBase.RowIndex : new RowColumnIndex().RowIndex;
            rowcolumnIndex.ColumnIndex = treeGridCell != null ? treeGridCell.ColumnBase.ColumnIndex : new RowColumnIndex().ColumnIndex;

#if !WPF
            if (checkBox.IsThreeState)
            {
                SetIsChecked(checkBox, checkBox.IsChecked);
            }
            if (!rowcolumnIndex.IsEmpty)
            {
                this.TreeGrid.SelectionController.HandlePointerOperations(new GridPointerEventArgs(PointerOperation.Pressed, null), rowcolumnIndex);
                this.TreeGrid.SelectionController.HandlePointerOperations(new GridPointerEventArgs(PointerOperation.Released, null), rowcolumnIndex);
            }
#endif
            TreeGrid.RaiseCurrentCellValueChangedEvent(new TreeGridCurrentCellValueChangedEventArgs(TreeGrid)
            {
                RowColumnIndex = rowcolumnIndex, Record = checkBox.DataContext, Column = treeGridCell.ColumnBase.TreeGridColumn
            });

            if (HasCurrentCellState)
            {
                BindingExpression = this.CurrentCellRendererElement.GetBindingExpression(ToggleButton.IsCheckedProperty);
            }
            //when check or uncheck the checkbox, setter property of checkbox column fires two times in the Model class.
            //while loading, we set the updatesourcetrigger as explicit for checkboxcolumn if we set updatetrigger as PropertyChanged in sample for checkboxcolumn.
            //so skips the below call by checking the updatesourcetrigger.
#if WPF
            if (treeGridCell.ColumnBase.TreeGridColumn.isValueMultiBinding)
            {
                if (BindingExpression != null && (treeGridCell != null && (treeGridCell.ColumnBase.TreeGridColumn.ValueBinding as MultiBinding).UpdateSourceTrigger == UpdateSourceTrigger.Explicit))
                {
                    BindingExpression.UpdateSource();
                }
            }
            else if (BindingExpression != null && (treeGridCell != null && (treeGridCell.ColumnBase.TreeGridColumn.ValueBinding as Binding).UpdateSourceTrigger == UpdateSourceTrigger.Explicit))
            {
                BindingExpression.UpdateSource();
            }
#else
            if (BindingExpression != null && (treeGridCell != null && (treeGridCell.ColumnBase.TreeGridColumn.ValueBinding as Binding).UpdateSourceTrigger == UpdateSourceTrigger.Explicit))
            {
                BindingExpression.UpdateSource();
            }
#endif
        }
        /// <summary>
        /// Called when the UnBoundRow cell gets end edited.
        /// </summary>
        /// <param name="dc">DataColumnBase Which holds GridColumn, RowColumnIndex and GridCell</param>
        /// <param name="record">DataContext of the row</param>
        /// <param name="canResetBinding">Reset Binding the CurrentCell</param>
        /// <returns></returns>
        public override bool EndEdit(DataColumnBase dc, object record, bool canResetBinding = false)
        {
            var cellRowColumnIndex = new RowColumnIndex(dc.RowIndex, dc.ColumnIndex);
            var cellElement        = dc.ColumnElement;
            var column             = dc.GridColumn;

            if (!this.HasCurrentCellState)
            {
                return(false);
            }
            if (!this.IsInEditing)
            {
                return(false);
            }
            if (this.SupportsRenderOptimization)
            {
#if WPF
                E uiElement = null;
                if (!UseOnlyRendererElement && cellElement is GridCell)
                {
                    uiElement = (E)((cellElement as GridCell).Content is FrameworkElement ? (cellElement as GridCell).Content as FrameworkElement : cellElement);
                }
                else
                {
                    uiElement = cellElement as E;
                }
                uiElement.PreviewLostKeyboardFocus -= OnLostKeyboardFocus;
#endif
                //this.IsFocused = false;
                this.SetFocus(false);

                GridUnBoundRowEventsArgs gridUnBoundRowEventsArgs = (cellElement as GridCell).ColumnBase.GridUnBoundRowEventsArgs;
                var dataColumn = (cellElement as GridCell).ColumnBase;

                OnEditingComplete(dataColumn, CurrentCellRendererElement);
                if (!UseOnlyRendererElement && cellElement == null)
                {
                    throw new Exception("Cell Element will not be get null for any case");
                }
                OnUnloadUIElements(dataColumn);

                OnPrepareUIElements(dataColumn, record, false);

                if (gridUnBoundRowEventsArgs != null && !gridUnBoundRowEventsArgs.hasCellTemplate)
                {
                    UpdateCurrentCellState((cellElement as GridCell).Content as FrameworkElement, false);
                }
                else
                {
                    UpdateCurrentCellState(cellElement as FrameworkElement, false);
                }
            }
            else
            {
                UpdateCurrentCellState(this.CurrentCellRendererElement, false);
            }

            return(!this.IsInEditing);
        }
 public override void MoveCurrentCell(RowColumnIndex rowColumnIndex, bool needToClearSelection = true)
 {
     if (TreeGrid.CheckBoxSelectionMode == CheckBoxSelectionMode.SelectOnCheck)
     {
         throw new InvalidOperationException("It is not possible to move current cell programmatically when CheckBoxSelectionMode is SelectOnlyOnCheckBoxClick");
     }
     base.MoveCurrentCell(rowColumnIndex, needToClearSelection);
 }
 public override void HandlePointerOperations(GridPointerEventArgs args, RowColumnIndex rowColumnIndex)
 {
     if (TreeGrid.CheckBoxSelectionMode == CheckBoxSelectionMode.SelectOnCheck)
     {
         return;
     }
     base.HandlePointerOperations(args, rowColumnIndex);
 }
        public void InstanceDescriptorRoundtrip()
        {
            var index = new RowColumnIndex(1, 2);
            var converter = new RowColumnIndexConverter();

            Assert.IsTrue(converter.CanConvertTo(null, typeof(InstanceDescriptor)));
            var convertTo = converter.ConvertTo(index, typeof(InstanceDescriptor));
            Assert.IsInstanceOf<InstanceDescriptor>(convertTo);

            Assert.IsTrue(converter.CanConvertFrom(null, typeof(InstanceDescriptor)));

            var convertFrom = converter.ConvertFrom(convertTo);
            Assert.AreEqual(index, convertFrom);
        }
        public void StringRoundtrips()
        {
            var index = new RowColumnIndex(1, 2);
            var converter = new RowColumnIndexConverter();

            Assert.IsTrue(converter.CanConvertTo(null, typeof(string)));
            var convertTo = converter.ConvertTo(index, typeof(string));
            Assert.AreEqual("R1 C2", convertTo);

            Assert.IsTrue(converter.CanConvertFrom(null, typeof(string)));

            var convertFrom = converter.ConvertFrom(convertTo);
            Assert.AreEqual(index, convertFrom);
        }
Example #33
0
 public static void SetIndex(this DataGrid element, RowColumnIndex? value)
 {
     element.SetValue(IndexProperty, value);
 }
Example #34
0
        private static void OnCellItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (Equals(d.GetValue(IsUpdatingProperty), BooleanBoxes.True))
            {
                return;
            }

            d.SetValue(IsUpdatingProperty, BooleanBoxes.True);
            try
            {
                var dataGrid = (DataGrid)d;
                dataGrid.UnselectAllCells();
                if (e.NewValue == null)
                {
                    dataGrid.SetIndex(null);
                    return;
                }

                for (var r = 0; r < dataGrid.Items.Count; r++)
                {
                    for (var c = 0; c < dataGrid.Columns.Count; c++)
                    {
                        var column = dataGrid.Columns[c];
                        var cellItem = GetCellItem(column, dataGrid.Items[r]);
                        if (Equals(cellItem, e.NewValue))
                        {
                            var index = new RowColumnIndex(r, c);
                            dataGrid.SetIndex(index);
                            var cell = dataGrid.GetCell(index);
                            cell.IsSelected = true;
                            return;
                        }
                    }
                }

                dataGrid.SetIndex(null);
            }
            finally
            {
                d.SetValue(IsUpdatingProperty, BooleanBoxes.False);
            }
        }
Example #35
0
        private static DataGridCell GetCell(this DataGrid dataGrid, RowColumnIndex index)
        {
            if (index.Column < 0 || index.Column >= dataGrid.Columns.Count)
            {
                return null;
            }

            if (index.Row < 0 || index.Row >= dataGrid.ItemContainerGenerator.Items.Count)
            {
                return null;
            }

            var dataGridColumn = dataGrid.Columns[index.Column];
            var row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(index.Row);
            var content = dataGridColumn.GetCellContent(row);
            var cell = content.Ancestors()
                              .OfType<DataGridCell>()
                              .FirstOrDefault();

            return cell;
        }