在开发本公司一个经营分析系统立,需要应用到一些二维表头,引用了网上的一个控件,效果还可以。
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Reflection;
using System.Windows.Forms;
using GoodsReportManage.ItemClass;
using System.Data.SqlClient;
using Microsoft.Office.Core;
using Microsoft.VisualBasic;
using Excel = Microsoft.Office.Interop.Excel;
using GoodsReportManage.SQLDML;
namespace GoodsReportManage
{
public partial class headview : Form
{
public headview()
{
InitializeComponent();
}
SqlBaseClass G_SqlClass = new SqlBaseClass(); //声明数据库操作类的对象
WinOperationClass G_OperationForm = new WinOperationClass(); //声明对窗体操作的类对象
//int G_Int_status; //保存工具栏按钮操作状态
private void btnQuery_Click(object sender, EventArgs e)
{
string SQLtxt;
SQLtxt = "EXEC BMS_BUSINESS_GETALLDATA_YEAR";
SQLtxt += " '" + txtPeriod1.Text + "'";
treeView1.Nodes.Clear(); ;
if (txtPeriod1.Text.Length < 4)
{
MessageBox.Show("输入查询区间" + txtPeriod1.Text + "格式错误,正确格式应为200800");
return;
}
this.headerUnitView1.DataSource = G_SqlClass.GetDs(SQLtxt).Tables[0];
this.headerUnitView1.Columns[0].HeaderText = "科目代码";
this.headerUnitView1.Columns[1].HeaderText = "科目名称";
this.headerUnitView1.Columns[2].HeaderText = "单位";
TreeNode treeNode1 = new System.Windows.Forms.TreeNode("科目代码");
this.treeView1.Nodes.Add(treeNode1);
TreeNode treeNode2 = new System.Windows.Forms.TreeNode("科目名称");
this.treeView1.Nodes.Add(treeNode2);
TreeNode treeNode3 = new System.Windows.Forms.TreeNode("单位");
this.treeView1.Nodes.Add(treeNode3);
//--低层相同子列
for (int i = 3; i < headerUnitView1.Columns.Count-1;i=i+3 )
{
string headtxt = headerUnitView1.Columns[i].HeaderText.ToString();
TreeNode treeNode = new System.Windows.Forms.TreeNode(headtxt);
this.treeView1.Nodes.Add(treeNode);
int s = i / 3 + 2;
TreeNode treeNode5 = new System.Windows.Forms.TreeNode("计划数");
TreeNode treeNode6 = new System.Windows.Forms.TreeNode("完成数");
TreeNode treeNode7 = new System.Windows.Forms.TreeNode("完成率");
this.treeView1.Nodes[s].Nodes.Add(treeNode5);
this.treeView1.Nodes[s].Nodes.Add(treeNode6);
this.treeView1.Nodes[s].Nodes.Add(treeNode7);
}
this.headerUnitView1.ColumnDeep = 2;
}
}
}