日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WinForm DataGrid的功能扩展及实现 (已写完)

發布時間:2024/1/18 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WinForm DataGrid的功能扩展及实现 (已写完) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

??????? 你是否在開發WinForm應用程序時,通常使用DataGrid來作為數據的層現,是否會用到DataGrid分頁,添加序號,添加全選,反選功能,有時還會用到不同數據顯示不同的顏色.DataGridGost為我們做了這一切,你只需要簡單的設置,幾乎不用寫一行代碼就能輕松完成.下面我們一起來進入DataGridGost神奇的世界

[關鍵詞]DataGrid,DataGrid全選,自動添加序號.

1.系統概述
????? DataGridGos主要是封裝了對分頁,添加自動編號,添加全選列,轉義列(比如,為2時顯示加急,3顯示不加急),指定條件的行著色等功能,指定條件的行才能被鉤選.

2、部份實現代碼

??? 添加全選列

???? private ? void ?AddBoolColumnToTableStyle()
????????{
????????????DataGridColorBoolColumn?dgbolChoose_temp;
????????????dgbolChoose_temp?
= ? new ?DataGridColorBoolColumn();

????????????
//
????????????
// dgbolChoose_temp選擇列
????????????
//
????????????dgbolChoose_temp.HeaderText? = ?_CheckBoxTitle;
????????????dgbolChoose_temp.MappingName?
= ? " NetlmChoose_2006 " ;
????????????dgbolChoose_temp.FalseValue?
= ? false ;
????????????dgbolChoose_temp.NullValue?
= ? "" ;
????????????dgbolChoose_temp.TrueValue?
= ? true ;
????????????dgbolChoose_temp.Width?
= ?_ChekcBoxWidth;

????????????
int ?size? = ?_CurrentDataGrid.TableStyles[ 0 ].GridColumnStyles.Count? + ? 1 ;
????????????DataGridColumnStyle[]?dgcsarry?
= ? new ?DataGridColumnStyle[size];
????????????dgcsarry[
0 ]? = ?dgbolChoose_temp;
????????????
for ?( int ?i? = ? 0 ;?i? < ?size? - ? 1 ;?i ++ )
????????????{
????????????????dgcsarry[i?
+ ? 1 ]? = ?_CurrentDataGrid.TableStyles[ 0 ].GridColumnStyles[i];
????????????}

????????????_CurrentDataGrid.TableStyles[
0 ].GridColumnStyles.Clear();
????????????_CurrentDataGrid.TableStyles[
0 ].GridColumnStyles.AddRange(dgcsarry);
????????}


?添加自動編號列

???? private ? void ?AddSerNumColumnToTableStyle()
????????{
????????????DataGridColorTextColumn?dgSerNum_temp;
????????????dgSerNum_temp?
= ? new ?DataGridColorTextColumn();
????????????
????????????dgSerNum_temp.HeaderText?
= ? " 序號 " ;
????????????dgSerNum_temp.MappingName?
= ? " NetlmSerNumUID " ;
????????????dgSerNum_temp.Alignment?
= ?HorizontalAlignment.Center;
????????????dgSerNum_temp.Width?
= ?_SerNumWidth;

????????????
int ?size? = ?_CurrentDataGrid.TableStyles[ 0 ].GridColumnStyles.Count? + ? 1 ;
????????????DataGridColumnStyle[]?dgcsarry?
= ? new ?DataGridColumnStyle[size];
????????????dgcsarry[
0 ]? = ?dgSerNum_temp;
????????????
for ?( int ?i? = ? 0 ;?i? < ?size? - ? 1 ;?i ++ )
????????????{
????????????????dgcsarry[i?
+ ? 1 ]? = ?_CurrentDataGrid.TableStyles[ 0 ].GridColumnStyles[i];
????????????}

????????????_CurrentDataGrid.TableStyles[
0 ].GridColumnStyles.Clear();
????????????_CurrentDataGrid.TableStyles[
0 ].GridColumnStyles.AddRange(dgcsarry);
????????}


??????? 在對輸入的條件直接轉換為布爾值時,遇到些困難,開始我想調用CodeDom直接生成表達式的值,但這樣做并沒有成功。比如 UserName==shumi 其中UserName表示的是列名,需要dr["UserName"].ToString()來讀出列的值,而在CodeDom中并不能讀出列的值,不知道那位高手有好的解決方案。我的做法是自已寫了一個類似編譯原理中的詞法分析的類,采用四元式的方式分析表達式并求出布爾值,但由于學編譯原理的知識差不多全還給老師了,所以在對四元式進行DAG圖化簡時還存在一定的問題。

下面是部份實現代碼:
??

???? private ? bool ?GetBoolByWhere( string ?str,DataRow?dr)
????????{
????????????
// 將表達式分詞
????????????ArrayList?ary? = ?StrToBoolExpression.ConvertExpression(str);
????????????
????????????
for ( int ?i = 0 ;i < ary.Count;i ++ )
????????????{
????????????????
if (i < ary.Count - 1 ? && ? ! IsOperator(ary[i].ToString()))
????????????????{
????????????????????
// 如果是字段,取出字段所表示的值
???????????????????? if (ary[i + 1 ].ToString()? != " ! " ? && ?ary[i + 1 ].ToString() != " && " ? && ?ary[i + 1 ].ToString() != " || " )
????????????????????{
????????????????????????ary[i]?
= ?dr[ary[i].ToString()].ToString();
????????????????????}
????????????????}
????????????}
????????????
try
????????????{
????????????????
return ? bool .Parse(StrToBoolExpression.ComputePostfix(ary).ToString());
????????????}
????????????
catch
????????????{
????????????????
return ? false ;
????????????}
????????}

?

后記:
??????? 這幾天感冒了又拉肚子,好難受,從前天晚上都沒有吃過任何東西,今天終于吃了兩個雞蛋,身體開始好轉了,所以整理了這篇文章。先休息一下,下一篇我將介紹根據DataGridGost自動生成DataGridTableStyle的方法,并對自已開發的這個小工具使用方法做個簡單的介紹。這里先提供給大家下載,希望能給大家的開發帶來幫助.


文件下載:
?類庫文檔?????????????示例源代碼?????? DataGridTableStyle自動生成工具?

接著上午沒有寫完的說一下DataGridTableStyle自動生成工具的用法

?

軟件界面如上圖所示
設置好數據庫連接后單擊連接按扭,將加載當前數據庫中的所有表和字段注釋.在左邊鉤選需要生成的表,如果需要將,整型字段轉義(1,顯示為男,2顯示為女)就在相應的列名行鉤選轉義.在這里我設定主鍵是不能為轉義列的
上面的顯示就是用到了DataGridGhost

生成的代碼如下:

自動生成的代碼
?1//作者:舒密????http://netlm.cnblogs.com
?2//廣西師范學院????TCN工?作室
?3
?4using?System;
?5using?System;
?6using?System.Collections;
?7using?System.ComponentModel;
?8using?System.Drawing;
?9using?System.Data;
10using?System.Windows.Forms;
11using?Netlm.DataGridColumnGost;
12?
13namespace?DataTableStyles
14{
15????/**////?<summary>
16????///?RAccountRolesTableStyles?
17????///?</summary>

18????public?class?RAccountRolesTableStyles?:?System.Windows.Forms.DataGridTableStyle
19????{
20????????private?System.ComponentModel.Container?components?=?null;
21????????public?RAccountRolesTableStyles()
22????????{
23????????????InitializeComponent();
24????????}

25????????/**////?<summary>?
26????????///?清理所有正在使用的資源。
27????????///?</summary>

28????????protected?override?void?Dispose(?bool?disposing?)
29????????{
30????????????if(?disposing?)
31????????????{
32????????????????if(components?!=?null)
33????????????????{
34????????????????????components.Dispose();
35????????????????}

36????????????}

37????????????base.Dispose(?disposing?);
38????????}

39????????private?DataGridColorTextColumn????dgColID;
40????????private?DataGridColorTextColumn????dgColAccountGuid;
41????????private?DataGridColorTextColumn????dgColRoleGuid;
42
43????????public?void?InitializeComponent()
44????????{
45????????????this.dgColID?=?new?DataGridColorTextColumn();
46????????????this.dgColAccountGuid?=?new?DataGridColorTextColumn();
47????????????this.dgColRoleGuid?=?new?DataGridColorTextColumn();
48????
49
50????????????//
51????????????//dgColID?用戶角色關系表ID自動增加,
52????????????//
53????????????dgColID.Format?="";
54????????????dgColID.FormatInfo=null;
55????????????dgColID.HeaderText?="用戶角色關系表ID自動增加,";
56????????????dgColID.MappingName?="ID";
57????????????dgColID.Width?=75;
58????????????//
59????????????//dgColAccountGuid?用戶GUID
60????????????//
61????????????dgColAccountGuid.Format?="";
62????????????dgColAccountGuid.FormatInfo=null;
63????????????dgColAccountGuid.HeaderText?="用戶GUID";
64????????????dgColAccountGuid.MappingName?="AccountGuid";
65????????????dgColAccountGuid.Width?=75;
66????????????//
67????????????//dgColRoleGuid?角色GUID
68????????????//
69????????????dgColRoleGuid.Format?="";
70????????????dgColRoleGuid.FormatInfo=null;
71????????????dgColRoleGuid.HeaderText?="角色GUID";
72????????????dgColRoleGuid.MappingName?="RoleGuid";
73????????????dgColRoleGuid.Width?=75;
74????????????//?
75????????????//?DataTableStyles
76????????????//?
77????????????this.GridColumnStyles.AddRange(new?System.Windows.Forms.DataGridColumnStyle[]?{
78??????????????????????????????????????????????????????????????????????????????????????????????this.dgColID,
79??????????????????????????????????????????????????????????????????????????????????????????????this.dgColAccountGuid,
80??????????????????????????????????????????????????????????????????????????????????????????????this.dgColRoleGuid
81??????????????????????????????????????????????????????????????????????????????????????????}
);
82????????}

83????}

84}

轉載于:https://www.cnblogs.com/netlm/archive/2006/09/03/493483.html

總結

以上是生活随笔為你收集整理的WinForm DataGrid的功能扩展及实现 (已写完)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。