private void UnHideColumns_Click(object sender, RoutedEventArgs e) { int sRange = 0; int eRange = 0; if (int.TryParse(startRange.Text, out sRange) && int.TryParse(endRange.Text, out eRange)) { if (sRange < 1 || eRange < 1 || (sRange + (eRange - sRange)) > cellGrid.ColumnCount - 1) { ShowErrorMessage("Enter valid start range and end range"); } else if (eRange < sRange) { ShowErrorMessage("Enter end range greater than start range"); } else { cellGrid.ColumnWidths.SetHidden(sRange, eRange, false); cellGrid.InvalidateCell(GridRangeInfo.Cols(sRange, eRange)); } } else { ShowErrorMessage("Enter a valid Range..."); } cellGrid.Focus(FocusState.Programmatic); }
private void SetColumnWidth_Click(object sender, RoutedEventArgs e) { int start = 0; int end = 0; double width = 0; if (int.TryParse(sRange.Text, out start) && int.TryParse(eRange.Text, out end) && Double.TryParse(HeightWidth.Text, out width)) { if (start < 1 || end < 1 || (start + (end - start)) > cellGrid.ColumnCount - 1) { ShowErrorMessage("Enter valid range"); } else if (end < start) { ShowErrorMessage("Enter end index greater than start index"); } else if (width < 1 || width > 255) { ShowErrorMessage("Column Width must be between 0 and 255"); } else { cellGrid.ColumnWidths.SetRange(start, end, width); cellGrid.InvalidateCell(GridRangeInfo.Cols(start, end)); } } else { ShowErrorMessage("Enter a valid range and valid value"); } cellGrid.Focus(FocusState.Programmatic); }
void _grid_CellClick(object sender, GridCellClickEventArgs e) { if ((string)_grid[e.RowIndex, e.ColIndex].CellType == "Header") { this._grid.Selections.Add(GridRangeInfo.Cols(e.ColIndex, e.ColIndex + 3)); } }
private void InitGrid() { var model = this.grid.Model; model.RowCount = 30; model.ColumnCount = 12; model.TableStyle.CellType = "Static"; System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(List <CustomersInfo>)); List <CustomersInfo> customers; using (Stream reader = new FileStream(@"Data\GridControl\Customers.xml", FileMode.Open)) { customers = (List <CustomersInfo>)xs.Deserialize(reader); } model[0, 1].CellValue = "CustomerID"; model[0, 2].CellValue = "ContactName"; model[0, 3].CellValue = "ContactTitle"; model[0, 4].CellValue = "CompanyName"; model[0, 5].CellValue = "City"; model[0, 6].CellValue = "Country"; model[0, 7].CellValue = "Address"; model[0, 8].CellValue = "Phone"; model[0, 9].CellValue = "ContactName"; model[0, 10].CellValue = "Orders"; model[0, 11].CellValue = "Fax"; for (int i = 1; i < model.RowCount; i++) { var customer = customers[i - 1]; model[i, 1].CellValue = customer.CustomerID; model[i, 3].CellValue = customer.ContactTitle; model[i, 4].CellValue = customer.CompanyName; model[i, 5].CellValue = customer.City; model[i, 6].CellValue = customer.Country; model[i, 7].CellValue = customer.Address; model[i, 8].CellValue = customer.Phone; model[i, 9].CellValue = customer.ContactName; model[i, 10].CellValue = customer.Fax; model.RowHeights[i] = 30; int j = 2; var style = model[i, j]; style.ShowTooltip = true; style.CellValue = customer.ContactName; style.Background = new SolidColorBrush(Colors.NavajoWhite); style.CellValue2 = customer.Phone.Length > 0 ? customer.Phone : "None"; style.TooltipTemplateKey = "templateTooltip"; } model.ColumnWidths[0] = 30; model.ColumnWidths[2] = 150; model.ResizeColumnsToFit(GridRangeInfo.Cols(3, 5), GridResizeToFitOptions.NoShrinkSize); }
private void InitGrid() { var model = this.grid.Model; model.RowCount = 30; model.ColumnCount = 12; model.TableStyle.CellType = "Static"; var nw = new Northwind(string.Format("Data Source={0}", LayoutControl.FindFile("Northwind.sdf"))); var customers = nw.Customers.Skip(0).Take(30).ToList(); model[0, 1].CellValue = "CustomerID"; model[0, 2].CellValue = "ContactName"; model[0, 3].CellValue = "ContactTitle"; model[0, 4].CellValue = "CompanyName"; model[0, 5].CellValue = "City"; model[0, 6].CellValue = "Country"; model[0, 7].CellValue = "Address"; model[0, 8].CellValue = "Phone"; model[0, 9].CellValue = "ContactName"; model[0, 10].CellValue = "Orders"; model[0, 11].CellValue = "Fax"; for (int i = 1; i < model.RowCount; i++) { var customer = customers[i - 1]; model[i, 1].CellValue = customer.CustomerID; model[i, 3].CellValue = customer.ContactTitle; model[i, 4].CellValue = customer.CompanyName; model[i, 5].CellValue = customer.City; model[i, 6].CellValue = customer.Country; model[i, 7].CellValue = customer.Address; model[i, 8].CellValue = customer.Phone; model[i, 9].CellValue = customer.ContactName; model[i, 10].CellValue = customer.Fax; model.RowHeights[i] = 30; int j = 2; var style = model[i, j]; style.ShowTooltip = true; style.CellValue = customer.ContactName; style.Background = new SolidColorBrush(Colors.NavajoWhite); style.CellValue2 = customer.Phone.Length > 0 ? customer.Phone : "None"; style.TooltipTemplateKey = "templateTooltip"; } model.ColumnWidths[0] = 30; model.ColumnWidths[2] = 150; model.ResizeColumnsToFit(GridRangeInfo.Cols(3, 5), GridResizeToFitOptions.NoShrinkSize); }
/// <summary> /// Grid Settings for better look and feel /// </summary> private void GridSettings() { this.gridControl1.RowCount = this.dataSet11.Customers.Rows.Count; this.gridControl1.ColCount = this.dataSet11.Customers.Columns.Count; this.gridControl1.PopulateValues(GridRangeInfo.Cells(1, 1, gridControl1.RowCount, gridControl1.ColCount), dataSet11.Customers); this.gridControl1.PopulateHeaders(GridRangeInfo.Cells(0, 1, 1, gridControl1.ColCount), dataSet11.Customers); this.gridControl1.ColWidths.ResizeToFit(GridRangeInfo.Cols(1, gridControl1.ColCount)); this.gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Cols(1, gridControl1.RowCount)); this.gridControl1.BackColor = Color.White; this.gridControl1.AlphaBlendSelectionColor = Color.CornflowerBlue; this.gridControl1.GridVisualStyles = Syncfusion.Windows.Forms.GridVisualStyles.Metro; //Used to set default row height this.gridControl1.DefaultRowHeight = 22; this.gridControl1.Model.Options.DisplayEmptyColumns = true; this.gridControl1.Model.Options.DisplayEmptyRows = true; //tab key navigation set as false to move the next control this.gridControl1.WantTabKey = false; for (int i = 1; i < this.gridControl1.ColCount; i++) { Regex rex = new Regex(@"\p{Lu}"); string MappingName = this.gridControl1[0, i].Text; int index = rex.Match(MappingName.Substring(1)).Index; string name = ""; while (index > 0) { name += MappingName.Substring(0, index + 1) + " "; string secondName = MappingName.Substring(index + 1); index = rex.Match(secondName.Substring(1)).Index; while (index > 0) { name += secondName.Substring(0, index + 1) + " "; index = rex.Match(MappingName.Substring(name.Replace(" ", "").Length).Substring(1)).Index; } } name += MappingName.Substring(name.Replace(" ", "").Length); this.gridControl1[0, i].Text = name; } }
private void radioButtonAdv12_CheckChanged(object sender, EventArgs e) { // ResizeToFit - Resizes a range of rows or column to optimally fit // contents of the specified range of cells. this.gridControl1.ColWidths.ResizeToFit(GridRangeInfo.Cols(1, 5)); }
private void Button_Click_1(object sender, RoutedEventArgs e) { this.grid.Model.ResizeColumnsToFit(GridRangeInfo.Cols(6, 8), GridResizeToFitOptions.NoShrinkSize | GridResizeToFitOptions.IncludeCellsWithinCoveredRange); }
private void InitializeGrid() { #region Style prerequistes GridStyleInfo standard = gridControl1.BaseStylesMap["Standard"].StyleInfo; standard.Font.Bold = false; standard.Font.Facename = "Verdana"; //"Verdana"; standard.Font.Size = 10; standard.TextColor = Color.FromArgb(240, 0, 21, 84); gridControl1.Font = new System.Drawing.Font("Verdana", 8.5F); // grab some images... ImageList imageList = new ImageList(); imageList.Images.Add(SystemIcons.Warning.ToBitmap()); imageList.Images.Add(SystemIcons.Application.ToBitmap()); imageList.Images.Add(SystemIcons.Asterisk.ToBitmap()); imageList.Images.Add(SystemIcons.Error.ToBitmap()); imageList.Images.Add(SystemIcons.Exclamation.ToBitmap()); imageList.Images.Add(SystemIcons.Hand.ToBitmap()); imageList.Images.Add(SystemIcons.Information.ToBitmap()); imageList.Images.Add(SystemIcons.Question.ToBitmap()); //standard.ImageList = imageList; Icon icon = new Icon(GetType().Module.Assembly.GetManifestResourceStream("EditorCellDemo.gridform.ico")); imageList.Images.Add(icon.ToBitmap()); icon = new Icon(GetType().Module.Assembly.GetManifestResourceStream("EditorCellDemo.toolsform.ico")); imageList.Images.Add(icon.ToBitmap()); standard.ImageList = imageList; #endregion #region Codes to apply celltypes in Grid this.gridControl1.BeginUpdate(); gridControl1.TableStyle.FloatCell = true; gridControl1.FloatCellsMode = GridFloatCellsMode.BeforeDisplayCalculation; #region Style declaration GridStyleInfo headerstyle = new GridStyleInfo(); headerstyle.Font.Size = 12; headerstyle.Font.Bold = true; headerstyle.VerticalAlignment = GridVerticalAlignment.Middle; headerstyle.HorizontalAlignment = GridHorizontalAlignment.Center; headerstyle.CellType = GridCellTypeName.Static; GridStyleInfo subheaderstyle = new GridStyleInfo(); subheaderstyle.Font.Bold = true; subheaderstyle.VerticalAlignment = GridVerticalAlignment.Middle; subheaderstyle.HorizontalAlignment = GridHorizontalAlignment.Center; subheaderstyle.CellType = GridCellTypeName.Static; subheaderstyle.TextColor = Color.Gray; gridControl1.Model.ColWidths[4] = 90; gridControl1.Model.ColWidths[6] = 100; #endregion #region TextBox Cells gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(1, 1, 2, gridControl1.ColCount)); gridControl1[1, 1] = headerstyle; gridControl1[1, 1].Text = "TextBox Cells"; int rowIndex = 3, colIndex = 4; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount)); gridControl1[rowIndex, 1] = subheaderstyle; gridControl1[rowIndex, 1].Text = "TextBox Cells - represents the default textbox control in a cell as used for in - place editing"; rowIndex++; gridControl1[rowIndex, colIndex].Text = "TextBox"; gridControl1[rowIndex, colIndex].CellType = GridCellTypeName.TextBox; gridControl1[rowIndex, colIndex + 2].Text = "TextBox/Image"; gridControl1[rowIndex, colIndex + 2].CellType = GridCellTypeName.TextBox; gridControl1[rowIndex, colIndex + 2].ImageIndex = 9; gridControl1.Model.ColWidths.ResizeToFit(GridRangeInfo.Col(colIndex + 2)); #endregion #region MaskEditCells rowIndex += 2; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex + 1, gridControl1.ColCount)); gridControl1[rowIndex, 1] = headerstyle; gridControl1[rowIndex, 1].Text = "MaskEdit Cells"; rowIndex++; rowIndex++; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount)); gridControl1[rowIndex, 1] = subheaderstyle; gridControl1[rowIndex, 1].Text = "MaskEdit Cells - allow to mask any cell that permits valid inputs & also control the inputs values"; rowIndex++; rowIndex++; gridControl1[rowIndex, colIndex].Text = "Date Format"; gridControl1[rowIndex, colIndex + 2].CellType = GridCellTypeName.MaskEdit; gridControl1[rowIndex, colIndex + 2].MaskEdit.Mask = "99-99-99"; gridControl1[rowIndex, colIndex + 2].FloatCell = true; rowIndex++; rowIndex++; gridControl1[rowIndex, colIndex].Text = "First Name"; GridStyleInfo style1 = gridControl1[rowIndex, colIndex + 2]; GridMaskEditInfo maskedEditStyle1 = style1.MaskEdit; rowIndex++; rowIndex++; gridControl1[rowIndex, colIndex].Text = "Last Name"; GridStyleInfo style2 = gridControl1[rowIndex, colIndex + 2]; GridMaskEditInfo maskedEditStyle2 = style2.MaskEdit; rowIndex++; rowIndex++; gridControl1[rowIndex, colIndex].Text = "Telephone"; GridStyleInfo style3 = gridControl1[rowIndex, colIndex + 2]; GridMaskEditInfo maskedEditStyle3 = style3.MaskEdit; rowIndex++; rowIndex++; gridControl1[rowIndex, colIndex].Text = "Social Security"; GridStyleInfo style4 = gridControl1[rowIndex, colIndex + 2]; GridMaskEditInfo maskedEditStyle4 = style4.MaskEdit; #region MaskEditBoxes // // maskedEditBox1 // style1.CellType = "MaskEdit"; maskedEditStyle1.AllowPrompt = false; maskedEditStyle1.ClipMode = Syncfusion.Windows.Forms.Tools.ClipModes.ExcludeLiterals; style1.CultureInfo = new System.Globalization.CultureInfo("en-US"); maskedEditStyle1.DateSeparator = '-'; maskedEditStyle1.Mask = ">C<CCCCCCCCCCCC"; style1.MaxLength = 13; style1.AutoSize = true; maskedEditStyle1.SpecialCultureValue = Syncfusion.Windows.Forms.Tools.SpecialCultureValues.None; maskedEditStyle1.UseLocaleDefault = false; maskedEditStyle1.UseUserOverride = true; // // maskedEditBox2 // style2.CellType = "MaskEdit"; maskedEditStyle2.AllowPrompt = false; maskedEditStyle2.ClipMode = Syncfusion.Windows.Forms.Tools.ClipModes.IncludeLiterals; style2.CultureInfo = new System.Globalization.CultureInfo("en-US"); maskedEditStyle2.DateSeparator = '-'; maskedEditStyle2.Mask = "CCCCCCCCCCCCC"; style2.MaxLength = 13; maskedEditStyle2.SpecialCultureValue = Syncfusion.Windows.Forms.Tools.SpecialCultureValues.None; style2.Text = "_____________"; maskedEditStyle2.UseLocaleDefault = false; maskedEditStyle2.UseUserOverride = true; // // maskedEditBox3 // style3.CellType = "MaskEdit"; maskedEditStyle3.AllowPrompt = false; maskedEditStyle3.ClipMode = Syncfusion.Windows.Forms.Tools.ClipModes.IncludeLiterals; style3.CultureInfo = new System.Globalization.CultureInfo("en-US"); maskedEditStyle3.DateSeparator = '-'; maskedEditStyle3.Mask = "(999) 999 - 9999"; style3.MaxLength = 16; maskedEditStyle3.SpecialCultureValue = Syncfusion.Windows.Forms.Tools.SpecialCultureValues.None; style3.Text = "(___) ___ - ____"; maskedEditStyle3.UseLocaleDefault = false; maskedEditStyle3.UseUserOverride = true; // // maskedEditBox4 // style4.CellType = "MaskEdit"; maskedEditStyle4.AllowPrompt = false; maskedEditStyle4.ClipMode = Syncfusion.Windows.Forms.Tools.ClipModes.IncludeLiterals; style4.CultureInfo = new System.Globalization.CultureInfo("en-US"); maskedEditStyle4.DateSeparator = '-'; maskedEditStyle4.Mask = "999-99-9999"; style4.MaxLength = 11; maskedEditStyle4.SpecialCultureValue = Syncfusion.Windows.Forms.Tools.SpecialCultureValues.None; style4.Text = "___-__-____"; maskedEditStyle4.UseLocaleDefault = false; maskedEditStyle4.UseUserOverride = true; #endregion #endregion #region NumericUpDown rowIndex++; rowIndex++; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex + 1, gridControl1.ColCount)); gridControl1[rowIndex, 1] = headerstyle; gridControl1[rowIndex, 1].Text = "NumericUpDown Cells"; rowIndex += 3; // Wrapping, Range 0-20 gridControl1[rowIndex, colIndex].Text = "With wrapping"; gridControl1[rowIndex, colIndex + 2].CellType = GridCellTypeName.NumericUpDown; gridControl1[rowIndex, colIndex + 2].Text = "5"; gridControl1[rowIndex, colIndex + 2].HorizontalAlignment = GridHorizontalAlignment.Right; gridControl1[rowIndex, colIndex + 2].NumericUpDown = new GridNumericUpDownCellInfo(0, 20, 5, 1, true); rowIndex++; rowIndex++; gridControl1[rowIndex, colIndex].Text = "Without wrapping"; gridControl1[rowIndex, colIndex + 2].CellType = GridCellTypeName.NumericUpDown; gridControl1[rowIndex, colIndex + 2].Text = "5"; gridControl1[rowIndex, colIndex + 2].NumericUpDown = new GridNumericUpDownCellInfo(1, 20, 1, 1, false); gridControl1[rowIndex, colIndex + 2].HorizontalAlignment = GridHorizontalAlignment.Right; #endregion #region Currency Cells rowIndex++; rowIndex++; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex + 1, gridControl1.ColCount)); gridControl1[rowIndex, 1] = headerstyle; gridControl1[rowIndex, 1].Text = "Currency Cells"; rowIndex++; rowIndex++; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount)); gridControl1[rowIndex, 1] = subheaderstyle; gridControl1[rowIndex, 1].Text = "Supports setting patterns to display (+), (-) numbers, grouping digits & decimal separators"; #region CurrentStyle Settings GridStyleInfo currencyStyle = new GridStyleInfo(); currencyStyle.CellType = GridCellTypeName.Currency; currencyStyle.CurrencyEdit.ClipMode = CurrencyClipModes.ExcludeFormatting; // Set formatting properties currencyStyle.CurrencyEdit.NullString = ""; currencyStyle.CurrencyEdit.CurrencyDecimalDigits = 2; currencyStyle.CurrencyEdit.CurrencyDecimalSeparator = "."; currencyStyle.CurrencyEdit.CurrencyGroupSeparator = ","; currencyStyle.CurrencyEdit.CurrencyGroupSizes = new int[] { 3 }; currencyStyle.CurrencyEdit.CurrencyNumberDigits = 27; currencyStyle.CurrencyEdit.CurrencyPositivePattern = 0; //currencyStyle.CurrencyEdit.CurrencySymbol = (row % 2 == 0) ? "$ " : "DM "; currencyStyle.TextColor = System.Drawing.Color.Black; currencyStyle.CurrencyEdit.NegativeColor = System.Drawing.Color.Red; currencyStyle.CurrencyEdit.NegativeSign = "-"; currencyStyle.CurrencyEdit.PositiveColor = System.Drawing.Color.Black; currencyStyle.FloatCell = true; #endregion rowIndex++; rowIndex++; gridControl1[rowIndex, colIndex - 2] = currencyStyle; gridControl1[rowIndex, colIndex - 2].CellValue = 2; gridControl1[rowIndex, colIndex - 2].CurrencyEdit.CurrencyNegativePattern = 1; gridControl1[rowIndex, colIndex - 2].CurrencyEdit.CurrencySymbol = "$ "; gridControl1[rowIndex, colIndex] = currencyStyle; gridControl1[rowIndex, colIndex].CellValue = 4; gridControl1[rowIndex, colIndex].CurrencyEdit.CurrencyNegativePattern = 2; gridControl1[rowIndex, colIndex].CurrencyEdit.CurrencySymbol = "DM"; gridControl1[rowIndex, colIndex + 2] = currencyStyle; gridControl1[rowIndex, colIndex + 2].CellValue = -6; gridControl1[rowIndex, colIndex + 2].CurrencyEdit.CurrencyNegativePattern = 1; gridControl1[rowIndex, colIndex + 2].CurrencyEdit.CurrencySymbol = "$ "; gridControl1[rowIndex, colIndex + 4] = currencyStyle; gridControl1[rowIndex, colIndex + 4].CellValue = -8; gridControl1[rowIndex, colIndex + 4].CurrencyEdit.CurrencyNegativePattern = 2; gridControl1[rowIndex, colIndex + 4].CurrencyEdit.CurrencySymbol = "DM "; #endregion #region Password cells rowIndex++; rowIndex++; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex + 1, gridControl1.ColCount)); gridControl1[rowIndex, 1] = headerstyle; gridControl1[rowIndex, 1].Text = "Password Cells"; rowIndex++; rowIndex++; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount)); gridControl1[rowIndex, 1] = subheaderstyle; gridControl1[rowIndex, 1].Text = "Allows you to type a password, but only masking character like \" * \", will be displayed "; GridStyleInfo passwdStyle = new GridStyleInfo(); for (int row = 37; row <= 45; row++) { passwdStyle = gridControl1[row, 2]; passwdStyle.PasswordChar = '*'; passwdStyle.CellType = GridCellTypeName.OriginalTextBox; passwdStyle.Text = new string((char)(65 + row), row); passwdStyle = gridControl1[row, 3]; passwdStyle.CharacterCasing = CharacterCasing.Lower; passwdStyle.Text = new string((char)(65 + row), row); passwdStyle = gridControl1[row, 4]; passwdStyle.CharacterCasing = CharacterCasing.Upper; passwdStyle.Text = new string((char)(65 + row), row); } #endregion gridControl1.CheckBoxClick += new GridCellClickEventHandler(gridControl1_CheckBoxClick); gridControl1.Model.ColWidths.ResizeToFit(GridRangeInfo.Cols(1, 11)); gridControl1.Model.ColWidths[0] = (int)DpiAware.LogicalToDeviceUnits(35); this.gridControl1.EndUpdate(true); #endregion }