国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > 綜合 > 正文

手工創(chuàng)建datagrid的數(shù)據(jù)列(c# window)

2024-07-21 02:17:31
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
中國(guó)最大的web開(kāi)發(fā)資源網(wǎng)站及技術(shù)社區(qū),
 

筆者以前很少使用vs.net中的datagrid,原因是覺(jué)得不是很好用,昨天突然想起來(lái),用一個(gè)簡(jiǎn)單的類,來(lái)實(shí)現(xiàn)手工創(chuàng)建數(shù)據(jù)列,這樣可以自定義列名和綁定數(shù)據(jù)字段,使用起來(lái)比較方面的~~

類:exdatagrid.cs

using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;

namespace windowsapplication5
{
 /// <summary>
 /// exdatagrid 的摘要說(shuō)明。
 /// </summary>
 public class exdatagrid
 {
  private system.windows.forms.datagrid datagrid;
  private string strmapname;
  private static datagridtablestyle dgt;

//strmapname:表名;

  public exdatagrid(system.windows.forms.datagrid datagrid,string strmapname)
  {
   this.datagrid=datagrid;
   this.strmapname=strmapname;
   datagrid.tablestyles.clear(); 
   datagridtablestyle tblstyle = new datagridtablestyle();
   tblstyle.mappingname = this.strmapname;
   datagrid.tablestyles.add(tblstyle);
   dgt=tblstyle;
  }

//參數(shù):

//1--i:gridcolumnstyles;

//2--strmap:mappingname ;

//3--strheader:headertext 
  public static void createcols(int i,string strmap,string strheader)
  {
   createcols(i,strmap,strheader,80);
  }

//參數(shù):

//intwidth:數(shù)據(jù)列列寬
  public static void createcols(int i,string strmap,string strheader,int intwidth)
  {

//在這里可以設(shè)置列的樣式
   datagridcolumnstyle textcol = new datagridtextboxcolumn();
   datagridtablestyle tblstyle=dgt;
   tblstyle.gridcolumnstyles.add(textcol);
   tblstyle.gridcolumnstyles[i].mappingname = strmap;
   tblstyle.gridcolumnstyles[i].headertext = strheader;
   tblstyle.gridcolumnstyles[i].width = intwidth;
   tblstyle.gridcolumnstyles[i].nulltext = string.empty;
  }

 }
}

調(diào)用:

   this.datagrid1.setdatabinding(dataset, "tablename");
   exdatagrid edg =new exdatagrid(this.datagrid1,"tablename");

   exdatagrid.createcols(0,"productcode","產(chǎn)品編號(hào)");
   exdatagrid.createcols(1,"productname","產(chǎn)品名稱");
   exdatagrid.createcols(2,"productclass","產(chǎn)品類");


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 定边县| 北海市| 资溪县| 阿巴嘎旗| 扎赉特旗| 四会市| 洮南市| 巴楚县| 双城市| 吴江市| 金山区| 天峨县| 手机| 深水埗区| 阿巴嘎旗| 巴塘县| 濉溪县| 永州市| 城固县| 定南县| 宣汉县| 通江县| 长兴县| 宿州市| 杭锦后旗| 土默特左旗| 鄂托克前旗| 浦江县| 泰兴市| 保定市| 谢通门县| 宁明县| 南丹县| 丰宁| 山丹县| 宣恩县| 康乐县| 任丘市| 博湖县| 馆陶县| 额济纳旗|