表格控件如何实现自定义单元格类型

作者:控件中国网   出处:控件中国网   2015-10-26 14:38:09   阅读:6

这篇文章咱们主要介绍Essential Studio for Windows Forms套包里的Grid控件如何实现自定义单元格类型,Essential Studio for Windows Forms提供的表格控件支持多种自定义单元格类型:打开浏览类型、计算器、日历日程、时间采集、超链接、图片类型、滑动条、图表、下拉列表等,这些类型的单元格都是表格中常见的单元格类型,下面就如何在表格中实现这些自定义单元格类型做一一介绍:
 
1.设置表格控件单元格类型为下拉列表
//Creates and registers drop-down grid cells.
DropDownGridCellModel aModel = new DropDownGridCellModel(this.gridControl1.Model);
aModel.EmbeddedGrid = GridA;
gridControl1.CellModels.Add("GridADropCell", aModel);
//Sets the drop-downs in the cell.
this.gridControl1[rowIndex,1].Text = "Grid A";
this.gridControl1[rowIndex,1].CellType = "GridADropCell";
2.为表格控件设置图表类型的单元格
ChartStyleProperties csp;
this.gridControl1.CellModels.Add("ChartCell", new GridChartCellModel(this.gridControl1.Model));
style = this.gridControl1[8, 2];
style.CellType = "ChartCell";
csp = new ChartStyleProperties(style);
csp.ChartType = ChartSeriesType.Column;
csp.TitleText = "Chart Cell";
csp.Series3D = false;
csp.TitleAlignment = StringAlignment.Center;
3.设置某个单元格类型为滑动条
gridControl1.CellModels.Add("Slider", new SliderCellModel(gridControl1.Model));
GridStyleInfo style;
style = gridControl1[4, 5];
SliderStyleProperties sp = new SliderStyleProperties(style);
style.CellType = "Slider";
sp.Maximum = 40;
sp.Minimum = 0;
sp.TickFrequency = 8;
sp.LargeChange = 16;
sp.SmallChange = 4;
sp.Orientation = Orientation.Vertical;
4.设置某个单元格为图片类型,专门用于显示图片
RegisterCellModel.GridCellType(gridControl1, CustomCellTypes.PictureBox);
PictureBoxStyleProperties sp;
style = gridControl1[2, 2];
style.CellType = CustomCellTypes.PictureBox.ToString();
sp = new PictureBoxStyleProperties(style);
sp.Image = GetImage("one.jpg");
5.设置某个单元格为超链接类型
RegisterCellModel.GridCellType(gridControl1, CustomCellTypes.LinkLabelCell);
int rowIndex = 5;
gridControl1[rowIndex, 2].CellType = CustomCellTypes.LinkLabelCell.ToString();
gridControl1[rowIndex, 2].Text = "Syncfusion, Inc.";
gridControl1[rowIndex, 2].Font.Bold = true;
gridControl1[rowIndex, 2].Tag = "http://www.Syncfusion.com";
6.设置表格中某个单元格为时间采集类型
RegisterCellModel.GridCellType(gridControl1, CustomCellTypes.DateTimePicker);
this.gridControl1[4, 2].CellType = CustomCellTypes.DateTimePicker.ToString();
this.gridControl1[4, 2].CellValueType = typeof(DateTime);
this.gridControl1[4, 2].CellValue = DateTime.Now;
this.gridControl1[4, 2].Format = "MM/dd/yyyy hh:mm";
8.设置日历类型的单元格
GridStyleInfo style;
style = gridControl1[row, 2];
style.CellType = CustomCellTypes.Calendar.ToString();
style.Control = new MonthCalendar();
9.设置计算器类型的单元格
RegisterCellModel.GridCellType(gridControl1, CustomCellTypes.CalculatorTextBox);
CalculatorControl c2 = new CalculatorControl();
c2.BorderStyle = Border3DStyle.RaisedOuter;
c2.BackColor = Color.BlanchedAlmond;
style = gridControl1[6, 2];
style.CellType = CustomCellTypes.CalculatorTextBox.ToString();
style.Control = c2;
 
 
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat