C1FlexGrid 学习(1) - 博客文库 - 博客园
来源:互联网 发布:极客网络 编辑:程序博客网 时间:2024/05/28 23:20
Public Sub Subtotal(ByVal aggType As C1.Win.C1FlexGrid.AggregateEnum, ByVal level As Integer, ByVal groupOn As Integer, ByVal totalOn As Integer, ByVal caption As String)
.Subtotal()
整了两个小时才搞清楚C1FlexGrid.Subtotal(AggregateEnum.Sum, 0, 1, c, "Grand Total");各个参数的意思。
AggregateEnum.Sum : 对C1FlexGrid里面的数据求和。
0 : 对C1FlexGrid数据分组的第0层。
1: 是根据第 1 列数据进行分组
Grand Total: 第0层分组的头标题
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using C1.Win.C1FlexGrid;
namespace Subtotals
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private C1.Win.C1FlexGrid.C1FlexGrid _flex;
private System.Windows.Forms.CheckBox _chkAbove;
private System.Windows.Forms.CheckBox _chkGrand;
private System.Windows.Forms.CheckBox _chkDirection;
private System.Windows.Forms.CheckBox _chkRegion;
private System.Windows.Forms.Button _btnPrint;
private CheckBox checkBox1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this._flex = new C1.Win.C1FlexGrid.C1FlexGrid();
this._chkAbove = new System.Windows.Forms.CheckBox();
this._chkGrand = new System.Windows.Forms.CheckBox();
this._chkDirection = new System.Windows.Forms.CheckBox();
this._chkRegion = new System.Windows.Forms.CheckBox();
this._btnPrint = new System.Windows.Forms.Button();
this.checkBox1 = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this._flex)).BeginInit();
this.SuspendLayout();
//
// _flex
//
this._flex.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this._flex.ColumnInfo = "10,1,0,0,0,75,Columns:";
this._flex.Location = new System.Drawing.Point(8, 30);
this._flex.Name = "_flex";
this._flex.Rows.DefaultSize = 16;
this._flex.Size = new System.Drawing.Size(610, 317);
this._flex.StyleInfo = resources.GetString("_flex.StyleInfo");
this._flex.TabIndex = 0;
//
// _chkAbove
//
this._chkAbove.Checked = true;
this._chkAbove.CheckState = System.Windows.Forms.CheckState.Checked;
this._chkAbove.Location = new System.Drawing.Point(8, 7);
this._chkAbove.Name = "_chkAbove";
this._chkAbove.Size = new System.Drawing.Size(144, 15);
this._chkAbove.TabIndex = 1;
this._chkAbove.Text = "Subtotals Above Data";
this._chkAbove.CheckedChanged += new System.EventHandler(this._chk_CheckedChanged);
//
// _chkGrand
//
this._chkGrand.Checked = true;
this._chkGrand.CheckState = System.Windows.Forms.CheckState.Checked;
this._chkGrand.Location = new System.Drawing.Point(168, 7);
this._chkGrand.Name = "_chkGrand";
this._chkGrand.Size = new System.Drawing.Size(72, 15);
this._chkGrand.TabIndex = 1;
this._chkGrand.Text = "Grand";
this._chkGrand.CheckedChanged += new System.EventHandler(this._chk_CheckedChanged);
//
// _chkDirection
//
this._chkDirection.Checked = true;
this._chkDirection.CheckState = System.Windows.Forms.CheckState.Checked;
this._chkDirection.Location = new System.Drawing.Point(256, 7);
this._chkDirection.Name = "_chkDirection";
this._chkDirection.Size = new System.Drawing.Size(72, 15);
this._chkDirection.TabIndex = 1;
this._chkDirection.Text = "Direction";
this._chkDirection.CheckedChanged += new System.EventHandler(this._chk_CheckedChanged);
//
// _chkRegion
//
this._chkRegion.Checked = true;
this._chkRegion.CheckState = System.Windows.Forms.CheckState.Checked;
this._chkRegion.Location = new System.Drawing.Point(336, 7);
this._chkRegion.Name = "_chkRegion";
this._chkRegion.Size = new System.Drawing.Size(80, 15);
this._chkRegion.TabIndex = 1;
this._chkRegion.Text = "Region";
this._chkRegion.CheckedChanged += new System.EventHandler(this._chk_CheckedChanged);
//
// _btnPrint
//
this._btnPrint.Location = new System.Drawing.Point(487, 7);
this._btnPrint.Name = "_btnPrint";
this._btnPrint.Size = new System.Drawing.Size(72, 19);
this._btnPrint.TabIndex = 2;
this._btnPrint.Text = "&Print";
this._btnPrint.Click += new System.EventHandler(this._btnPrint_Click);
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(401, 6);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(80, 16);
this.checkBox1.TabIndex = 3;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
this.checkBox1.CheckedChanged += new System.EventHandler(this._chk_CheckedChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(626, 352);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this._btnPrint);
this.Controls.Add(this._chkAbove);
this.Controls.Add(this._flex);
this.Controls.Add(this._chkGrand);
this.Controls.Add(this._chkDirection);
this.Controls.Add(this._chkRegion);
this.Name = "Form1";
this.Text = "C1FlexGrid: Subtotals";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this._flex)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
// populate grid
Random rnd = new Random();
_flex.Rows.Count = 14;
_flex[0,1] = "Direction";
_flex[0,2] = "Region";
CellRange rg = _flex.GetCellRange(0,3,0,_flex.Cols.Count-1);
rg.Data = "Rnd";
for (int r = 1; r < _flex.Rows.Count; r++)
{
_flex[r,0] = r;
_flex[r,1] = (r < 7)? "Inbound": "Outbound";
_flex[r,2] = (r < 3)? "North": (r < 7)? "South": (r < 10)? "East": "West";
for (int c = 3; c < _flex.Cols.Count; c++)
{
_flex[r,c] = rnd.Next(1000);
_flex.Cols[c].Format = "#,###";
}
}
// set up styles
CellStyle s = _flex.Styles[CellStyleEnum.Subtotal0];
s.BackColor = Color.Black;
s.ForeColor = Color.White;
s.Font = new Font(_flex.Font, FontStyle.Bold);
s = _flex.Styles[CellStyleEnum.Subtotal1];
s.BackColor = Color.DarkBlue;
s.ForeColor = Color.White;
s = _flex.Styles[CellStyleEnum.Subtotal2];
s.BackColor = Color.DarkRed;
s.ForeColor = Color.White;
// more setup
_flex.AllowDragging = AllowDraggingEnum.None;
_flex.AllowEditing = false;
_flex.Cols[0].WidthDisplay /= 3;
_flex.Tree.Column = 1;
// show totals
UpdateTotals();
}
private void UpdateTotals()
{
// clear existing totals
_flex.Subtotal(AggregateEnum.Clear);
// calculate subtotals (three levels, totals on every column)
for (int c = 3; c < _flex.Cols.Count; c++)
{
if (_chkGrand.Checked)
_flex.Subtotal(AggregateEnum.Sum, 0, -1, c, "Grand Total");
if (_chkDirection.Checked)
_flex.Subtotal(AggregateEnum.Sum, 1, 1, c, "Total for {0}");
if (_chkRegion.Checked)
_flex.Subtotal(AggregateEnum.Sum, 2, 2, c, "Total for {0}");
if (checkBox1.Checked)
_flex.Subtotal(AggregateEnum.Sum, 1, 2, c, "Total for {0}");
}
// done, autosize columns to finish
_flex.AutoSizeCols();
}
private void _chk_CheckedChanged(object sender, System.EventArgs e)
{
// set subtotal position
_flex.SubtotalPosition = (_chkAbove.Checked)
? SubtotalPositionEnum.AboveData
: SubtotalPositionEnum.BelowData;
// and update totals
UpdateTotals();
}
private void _btnPrint_Click(object sender, System.EventArgs e)
{
PrintDocument pd = _flex.PrintParameters.PrintDocument;
pd.DefaultPageSettings.Landscape = true;
Margins m = pd.DefaultPageSettings.Margins;
m.Left = 25;
m.Right = 25;
m.Top = 25;
m.Bottom = 25;
_flex.PrintGrid("Subtotals",
PrintGridFlags.ShowPreviewDialog |
PrintGridFlags.FitToPage);
}
}
}
- C1FlexGrid 学习(1) - 博客文库 - 博客园
- C1FlexGrid打印与预览 - hz_yihang的专栏 - CSDN博客
- 博客园学习网站
- 学习类博客1!
- 学习博客
- 学习博客
- 学习博客
- 学习博客
- 博客---学习
- 学习博客
- 学习博客
- 学习博客
- 学习博客
- 学习博客
- 学习博客
- 学习博客
- 学习博客
- 学习博客
- Beyond compare应用
- 新编c#面试题大全
- 头文件包含的合理顺序
- ARM 入门笔记
- 【winform】拖拽文件,快速导入文件地址
- C1FlexGrid 学习(1) - 博客文库 - 博客园
- C1FlexGrid打印与预览 - hz_yihang的专栏 - CSDN博客
- 实用接口:IP地址、手机归属和身份证查询接口
- A*寻路算法
- VC通过命令行参数禁止用户双击运行exe
- 求指点
- 国内开源asp.netCMS汇总
- ccc
- 编写 Servlet 程序 - 3