国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 吉林省| 岑巩县| 佛坪县| 玉山县| 怀来县| 贡嘎县| 东莞市| 沂南县| 上虞市| 封丘县| 赞皇县| 新邵县| 昂仁县| 万州区| 哈尔滨市| 海淀区| 通化市| 称多县| 左云县| 石林| 米脂县| 阳朔县| 乳山市| 广西| 中江县| 晋城| 东阳市| 龙川县| 阳原县| 乌恰县| 卓尼县| 于田县| 邮箱| 临沧市| 江北区| 伊金霍洛旗| 明星| 平远县| 长武县| 来凤县| 策勒县|