示例#1
0
        /// <summary>
        /// Handles the QueryCellInfo event of the Model control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="Syncfusion.Windows.Controls.Grid.GridQueryCellInfoEventArgs"/> instance containing the event data.</param>
        void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs args)
        {
            var viewModel = this.AssociatedObject.DataContext as ViewModel;

            if (args.Cell.RowIndex != 0)
            {
                GridDataStyleInfo style = args.Style as GridDataStyleInfo;

                if (style.CellIdentity.TableCellType == GridDataTableCellType.GroupCaptionCell)
                {
                    if (args.Style.CellValue != null)
                    {
                        string country = style.CellIdentity.Group.Key.ToString();
                        var    pathLoc = viewModel.ProductsDetails.Where(o => o.Suppliers.Country == country);
                        if (pathLoc.Count() > 0)
                        {
                            var countryPath = pathLoc.ElementAt(0).Suppliers.Country;
                            args.Style.CellValue2          = "Images/" + countryPath + ".png";
                            args.Style.CellType            = "DataBoundTemplate";
                            args.Style.CellItemTemplateKey = "sampleTemplate";
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Handles the QueryCellInfo event of the Model control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Syncfusion.Windows.Controls.Grid.GridQueryCellInfoEventArgs"/> instance containing the event data.</param>
        void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
        {
            GridDataTableModel _gridDataTableModel = sender as GridDataTableModel;
            GridDataStyleInfo  styleinfo           = e.Style as GridDataStyleInfo;

            //Updating the Unbound row values based on calculated summary values
            if (styleinfo.CellIdentity.TableCellType == GridDataTableCellType.UnboundRecordCell)
            {
                e.Style.Background = Brushes.LightGray;
                e.Style.Foreground = Brushes.Black;
                e.Style.ReadOnly   = true;

                var columnIndex = _gridDataTableModel.ResolvePositionToVisibleColumnIndex(e.Style.ColumnIndex);
                if (columnIndex >= 0)
                {
                    var column = _gridDataTableModel.TableProperties.VisibleColumns[columnIndex];

                    if (column.MappingName == "Population")
                    {
                        e.Style.CellValue = PopulationSummary + ".00";
                    }
                    else if (column.MappingName == "Area")
                    {
                        e.Style.CellValue = AreaSummary + ".00";
                    }
                    else if (column.MappingName == "PopulationDensity")
                    {
                        e.Style.CellValue = PopulationDensitySummary + "";
                    }
                    else if (column.MappingName == "Status")
                    {
                        e.Style.CellValue = "Total count = " + TotoalCount_dataGrid1;
                    }
                    e.Style.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                }
            }
            //Updating the Unbound column value based on dictionary values
            if (styleinfo.CellIdentity.TableCellType == GridDataTableCellType.UnboundColumnCell)
            {
                var dictkey = (_gridDataTableModel.View.Records[styleinfo.CellIdentity.RecordIndex].Data as CountryDetails).CountryName;
                e.Style.CellValue = UnboundColumnDictionary_dataGrid1[dictkey];
            }
        }
        protected override bool ShouldGridTryToHandlePreviewKeyDown(KeyEventArgs e)
        {
            // return false to indicate the CurrentCellUIElement should handle the key
            // and the grid should ignore it.
            bool isControlKey = (e.KeyboardDevice.Modifiers & ModifierKeys.Control) != ModifierKeys.None;

            if (isControlKey)
            {
                return(true);
            }

            switch (e.Key)
            {
            case Key.Right:
            case Key.Left:
            case Key.Down:
            case Key.Up:
            {
                // otherwise, move caret within textbox when cell is not in edit-mode.
                return(!CurrentCell.IsEditing);
            }

            case Key.End:
            case Key.Home:
            {
                CurrentCell.BeginEdit(true);
                return(false);
            }

            case Key.Delete:
            {
                CurrentCell.BeginEdit(true);
                return(false);
            }

            case Key.Enter:
            {
                if (this.CurrentStyle != null)
                {
                    GridDataStyleInfo sif = this.CurrentStyle.GridModel[this.CurrentCell.RowIndex, this.CurrentCell.ColumnIndex] as GridDataStyleInfo;
                    if (sif != null && sif.CellIdentity.TableCellType != GridDataTableCellType.AddNewRecordCell)
                    {
                        e.Handled = true;
                    }
                    else if (sif != null && sif.CellIdentity.TableCellType == GridDataTableCellType.AddNewRecordCell && !CurrentCell.IsEditing)
                    {
                        e.Handled = true;
                    }
                }
                if (this.CurrentCell.IsEditing)
                {
                    CurrentCell.EndEdit();
                }
                CurrentCell.MoveRight();

                return(true);

                break;
            }

            case Key.Back:
            {
                CurrentCell.BeginEdit(true);
                return(false);
            }
            break;
            }

            return(base.ShouldGridTryToHandlePreviewKeyDown(e));
        }