Posted on 2012-04-07 12:45
牛哥哥 阅读(1598)
评论(0) 编辑 收藏
C# Code
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Data;
using System.Data.SqlClient;
namespace wang.lx
{
class HXGL_HXGL:Window
{
ListView lv;
dbHelper db = new dbHelper();
GridView gv;
GridViewColumn gvc;
public HXGL_HXGL()
{
Title = "横向项目管理";
Grid grid = new Grid();
SizeToContent = SizeToContent.Height;
Width = 750;
grid.Margin = new Thickness(10);
Content = grid;
RowDefinition rd = new RowDefinition();
rd.Height = GridLength.Auto;
grid.RowDefinitions.Add(rd);
rd = new RowDefinition();
rd.Height = GridLength.Auto;
grid.RowDefinitions.Add(rd);
WrapPanel wrap = new WrapPanel();
Button btn1 = new Button();
btn1.Content = "增加";
btn1.Click += HXGL_btnOnClick;
btn1.Height = btn1.Width = 40;
wrap.Children.Add(btn1);
Button btn2 = new Button();
btn2.Height = btn2.Width = 40;
btn2.Content = "修改";
wrap.Children.Add(btn2);
Button btn3 = new Button();
btn3.Height = btn3.Width = 40;
btn3.Content = "删除";
wrap.Children.Add(btn3);
grid.Children.Add(wrap);
ScrollViewer sv = new ScrollViewer();
sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
sv.Height = this.Height - btn1.Height - 10;
grid.Children.Add(sv);
Grid.SetRow(sv, 1);
lv = new ListView();
sv.Content = lv;
Data_Init();
gv = new GridView();
gv.AllowsColumnReorder = true;
gv.ColumnHeaderToolTip = "横向项目管理";
lv.View = gv;
//可以向如下方式添加,但相当繁琐,代码重复次数超过两次,最好写成函数
//gvc = new GridViewColumn();
//gvc.DisplayMemberBinding = new Binding("name");
//gvc.Header = "项目名称";
//gvc.Width = 100;
//gv.Columns.Add(gvc);
//gvc = new GridViewColumn();
//gvc.DisplayMemberBinding = new Binding("XMXH");
//gvc.Header = "项目序号";
//gvc.Width = 100;
//gv.Columns.Add(gvc);
//gvc = new GridViewColumn();
//gvc.DisplayMemberBinding = new Binding("fzr");
//gvc.Header = "负责人";
//gvc.Width = 100;
//gv.Columns.Add(gvc);
//gvc = new GridViewColumn();
//gvc.DisplayMemberBinding = new Binding("HTJF");
//gvc.Header = "合同经费";
//gvc.Width = 100;
//gv.Columns.Add(gvc);
//gvc = new GridViewColumn();
//gvc.DisplayMemberBinding = new Binding("DKJE");
//gvc.Header = "到款金额";
//gvc.Width = 100;
//gv.Columns.Add(gvc);
//利用数组批量添加,注意,此处必须和读取的字段大小写保持一致,否则无法显示
string[] bstr = {"Name","XMXH","FZR","HTJF","DKJE", "HTBH", "FZRYB", "SBJF", "DKSJ", "XMLB", "LXSJ", "QDRQ", "JTSJ", "WTDW", "YXQX", "XMJJ","XMWCQKJJ", "XMCJZ" };
string[] headstr = {"项目名称","项目序号","负责人","合同经费","到款金额", "合同编号", "负责人院别", "设备经费", "到款时间", "项目类别", "立项时间", "签订日期", "结题时间", "委托单位", "有效期限", "项目简介","项目完成情况简介", "项目参加者"};
AddColumn(bstr, headstr);
}
//批量添加函数
protected void AddColumn(string[] bstr, string[] headstr)
{
for(int i=0;i<bstr.Length;i++)
{
gvc = new GridViewColumn();
gvc.DisplayMemberBinding = new Binding(bstr[i]);
gvc.Header = headstr[i];
//gvc.Width = 100;
gv.Columns