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
                    });
                }
            }
        }
        /// <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
        }
示例#3
0
        protected virtual void CurrentRendererValueChanged()
        {
            var column = (TreeGrid.Columns[TreeGrid.ResolveToGridVisibleColumnIndex(CurrentCellIndex.ColumnIndex)]);

            TreeGrid.RaiseCurrentCellValueChangedEvent(new TreeGridCurrentCellValueChangedEventArgs(TreeGrid)
            {
                RowColumnIndex = CurrentCellIndex, Record = CurrentCellRendererElement.DataContext, Column = column
            });
            if (column.UpdateTrigger != UpdateSourceTrigger.PropertyChanged || BindingExpression == null)
            {
                return;
            }
            if (BindingExpression.DataItem == null)
            {
                return;
            }
            object oldValue = null;

            if (TreeGrid.View != null)
            {
                oldValue = TreeGrid.View.GetPropertyAccessProvider()
                           .GetValue(BindingExpression.DataItem, BindingExpression.ParentBinding.Path.Path);
            }


            BindingExpression.UpdateSource();
            object Text = null;

            if (TreeGrid.View != null)
            {
                Text = TreeGrid.View.GetPropertyAccessProvider()
                       .GetValue(BindingExpression.DataItem, BindingExpression.ParentBinding.Path.Path);
            }

            object newValue;
            string errorMessage;
            var    treeNode = TreeGrid.View.Nodes.GetNode(BindingExpression.DataItem);

            if (!TreeGrid.ValidationHelper.RaiseCurrentCellValidatingEvent(oldValue, Text, column, out newValue, CurrentCellIndex, CurrentCellElement, out errorMessage, BindingExpression.DataItem, treeNode))
            {
                return;
            }
            if (!ReferenceEquals(newValue, Text))
            {
                SetControlValue(newValue);
            }

            if (TreeGrid.GridValidationMode != GridValidationMode.None)
            {
                TreeGrid.ValidationHelper.ValidateColumn(BindingExpression.DataItem, BindingExpression.ParentBinding.Path.Path, (TreeGridCell)CurrentCellElement, CurrentCellIndex);
            }

            TreeGrid.ValidationHelper.RaiseCurrentCellValidatedEvent(oldValue, Text, column, errorMessage, BindingExpression.DataItem, treeNode);
        }
        /// <summary>
        /// Raises the <see cref="Syncfusion.UI.Xaml.TreeGrid.SfTreeGrid.CurrentCellValueChanged"/> event.
        /// </summary>
        /// <param name="treeGrid">
        /// The corresponding grid that contains the cell value changes .
        /// </param>
        /// <param name="dataColumn">
        /// The data column Which holds TreeGridColumn, RowColumnIndex and TreeGridCell.
        /// </param>
        public void RaiseCurrentCellValueChangedEvent(SfTreeGrid treeGrid, TreeDataColumnBase dataColumn)
        {
            var e = new TreeGridCurrentCellValueChangedEventArgs(treeGrid)
            {
                RowColumnIndex = new RowColumnIndex()
                {
                    RowIndex = dataColumn.RowIndex, ColumnIndex = dataColumn.ColumnIndex
                },
                Record = currentCellRendererElement.DataContext,
                Column = dataColumn.TreeGridColumn
            };

            TreeGrid.RaiseCurrentCellValueChangedEvent(e);
        }