C#中关于控件ComponentOne使用技巧
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
C#中关于控件ComponentOne使用技巧
1FlexGrid学习日志
1.1常用功能
设置值的方法,标题算入其中
_flex[1,2] = _flex[1,6] = "Q1"
行和列内容开始的属性,如c1FlexGrid1.Rows.Fixed=2表示,行标题为两行,第三行开始为内容.
c1FlexGrid1.Rows.Fixed
c1FlexGrid1.Cols.Fixed
设置cell边框的方式
_flex.Styles.Normal.Border.Style = BorderStyleEnum.Raised;
文字显示不完时候插入省略号
fg.Styles.Normal.Trimming = StringTrimming.EllipsisCharacter;//结尾插入省略号
fg.Styles.Normal.Trimming = StringTrimming.EllipsisPath; //中间插入省略号
选择方式
fg.SelectionMode = SelectionModeEnum.Cell;
在既要用多表头又要绑定数据集的时候的方法
可以先设定dataSource,然后再针对具体的表头cell修改值,如果先修改cell表头,在绑定dataSource的话,先前写的cell 表头就会被冲掉。
设置整体行高度、定行高度
_flex.Rows.MinSize = 25;_flex.Rows[0].Height = 30;
设置行、列是否允许编辑
flexSinter.Rows[1].AllowEditing = false;
是否允许某单元格编辑的方法
private void flexSinter_BeforeEdit(object sender, RowColEventArgs e)
{
if (e.Col == 4 && e.Row==1)
{
e.Cancel = true;
}
}
1.2设置行颜色和列颜色
CellStyle s = c1FlexGrid1.Styles.Add("RightAlign");
s = c1FlexGrid1.Styles.Add("Green");
s.BackColor = Color.Green;
s = c1FlexGrid1.Styles.Add("Red");
s.BackColor = Color.Red;
c1FlexGrid1.Rows[3].Style = c1FlexGrid1.Styles["Green"];
c1FlexGrid1.Cols[3].Style = c1FlexGrid1.Styles["Red "];
1.3设置复杂表头
//设置标题行占用多少行
c1FlexGrid1.Rows.Fixed = 3;
// set up to merge headers
c1FlexGrid1.AllowMerging = AllowMergingEnum.FixedOnly;
//设置表头允许合并
c1FlexGrid1.Cols[0].AllowMerging = c1FlexGrid1.Cols[1].AllowMerging = true;
c1FlexGrid1.Rows[0].AllowMerging = c1FlexGrid1.Rows[1].AllowMerging = true;
//设置表头的值相同
c1FlexGrid1[0, 0] = c1FlexGrid1[1, 0] = " ";
c1FlexGrid1[0, 1] = c1FlexGrid1[1, 1] = "Company";
//表头文字居中
CellStyle s = c1FlexGrid1.Styles.Add("CenterCenter");
s.TextAlign = TextAlignEnum.CenterCenter;
c1FlexGrid1.Rows[0].Style = c1FlexGrid1.Styles["CenterCenter"];
c1FlexGrid1.Rows[1].Style = c1FlexGrid1.Styles["CenterCenter"];
1.4设置内容合并
c1FlexGrid1.AllowMerging = AllowMergingEnum.Free;
for (int i = c1FlexGrid1.Rows.Fixed; i < c1FlexGrid1.Rows.Count; i++)
c1FlexGrid1.Rows[i].AllowMerging = true;
for (int i = c1FlexGrid1.Cols.Fixed; i < c1FlexGrid1.Cols.Count; i++)
c1FlexGrid1.Cols[i].AllowMerging = true;
1.5自定义绘制的方法----所有实现不了的样式都可以采用自定义绘制来实现
c1FlexGrid1.DrawMode = DrawModeEnum.OwnerDraw;
//开放如下事件,重绘内容写入其中
private void c1FlexGrid1_OwnerDrawCell(object sender, OwnerDrawCellEventArgs e) {
if (e.Row <= 1)
{
// select border color and thickness
Brush br = Brushes.Green;
int thick = 1;
// default painting
e.DrawCell();
// draw line below cell
if ((e.Row == 1 && e.Col > 0) || (e.Row == 0 && e.Col == 1)) {
Rectangle rc = e.Bounds;
rc.Y = rc.Bottom - thick;
rc.Height = thick;
e.Graphics.FillRectangle(br, rc);
}
// draw line to the right of the cell
if ((e.Row == 0 && e.Col == 0) || (e.Row == 0 && e.Col ==
1) ||
(e.Row == 0 && e.Col == 2) || (e.Row == 1 && e.Col == 5))
{
Rectangle rc = e.Bounds;
rc.X = rc.Right - thick;
rc.Width = thick;
e.Graphics.FillRectangle(br, rc);
}
}
}
1.6自由分组方式的做法
//初始设置
c1FlexGrid1.AllowMerging = AllowMergingEnum.Nodes;。