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

首頁 > 開發 > 綜合 > 正文

捕捉DataGrid的雙擊事件(C#版本)

2024-07-21 02:18:33
字體:
來源:轉載
供稿:網友
namespace datagriddoubleclick
{
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;

public class form1 : system.windows.forms.form
{
private system.windows.forms.datagrid datagrid1;
private dataset mydataset;
datetime gridmousedowntime;
private system.windows.forms.label label1;

private system.componentmodel.container components = null;

public form1()
{
initializecomponent();
gridmousedowntime = datetime.now;
setup();
}

private void setup()
{
// 用2個table和1和relation創建dataset
makedataset();
// 數據綁定
datagrid1.setdatabinding(mydataset, "customers");

//添加樣式
addcustomdatatablestyle();
}

private void makedataset()
{
// 創建dataset.
mydataset = new dataset("mydataset");

// 創建2個datatables.
datatable tcust = new datatable("customers");

// 創建兩個列,并添加到第一個表
datacolumn ccustid = new datacolumn("custid");
datacolumn ccustname = new datacolumn("custname");
datacolumn ccurrent = new datacolumn("custcity");
tcust.columns.add(ccustid);
tcust.columns.add(ccustname);
tcust.columns.add(ccurrent);

// 把tables添加到dataset.
mydataset.tables.add(tcust);


/* 計算tables.對每個客戶,創建datarow變量 */
datarow newrow1;

// 添加記錄到 customers table.
for(int i = 1; i < 4; i++)
{
newrow1 = tcust.newrow();
newrow1["custid"] = (100*i).tostring();
tcust.rows.add(newrow1);
}

tcust.rows[0]["custname"] = "【孟憲會之精彩世界】";
tcust.rows[1]["custname"] = "net_lover";
tcust.rows[2]["custname"] = "http://xml.sz.luohuedu.net/";


tcust.rows[0]["custcity"] = "北京";
tcust.rows[1]["custcity"] = "上海";
tcust.rows[2]["custcity"] = "河南";
}

private void addcustomdatatablestyle()
{
datagridtablestyle ts1 = new datagridtablestyle();
ts1.mappingname = "customers";
// 設置屬性
ts1.alternatingbackcolor = color.lightgray;

// 添加textbox列樣式,以便我們捕捉鼠標事件
datagridtextboxcolumn textcol = new datagridtextboxcolumn();
textcol.mappingname = "custid";
textcol.headertext = "序號";
textcol.width = 100;

//添加事件處理器
textcol.textbox.mousedown += new mouseeventhandler(textboxmousedownhandler);
textcol.textbox.doubleclick += new eventhandler(textboxdoubleclickhandler);
ts1.gridcolumnstyles.add(textcol);

textcol = new datagridtextboxcolumn();
textcol.mappingname = "custname";
textcol.headertext = "姓名";
textcol.width = 100;
//添加事件處理器
textcol.textbox.mousedown += new mouseeventhandler(textboxmousedownhandler);
textcol.textbox.doubleclick += new eventhandler(textboxdoubleclickhandler);
ts1.gridcolumnstyles.add(textcol);

textcol = new datagridtextboxcolumn();
textcol.mappingname = "custcity";
textcol.headertext = "地址";
textcol.width = 100;
//添加事件處理器
textcol.textbox.mousedown += new mouseeventhandler(textboxmousedownhandler);
textcol.textbox.doubleclick += new eventhandler(textboxdoubleclickhandler);
ts1.gridcolumnstyles.add(textcol);

datagrid1.tablestyles.add(ts1);

}

protected override void dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.dispose();
}
}
base.dispose( disposing );
}

#region windows form designer generated code
private void initializecomponent()
{
this.datagrid1 = new system.windows.forms.datagrid();
this.label1 = new system.windows.forms.label();
((system.componentmodel.isupportinitialize)(this.datagrid1)).begininit();
this.suspendlayout();
//
// datagrid1
//
this.datagrid1.captionbackcolor = system.drawing.systemcolors.info;
this.datagrid1.captionforecolor = system.drawing.systemcolors.windowtext;
this.datagrid1.captionvisible = false;
this.datagrid1.datamember = "";
this.datagrid1.headerforecolor = system.drawing.systemcolors.controltext;
this.datagrid1.location = new system.drawing.point(11, 9);
this.datagrid1.name = "datagrid1";
this.datagrid1.size = new system.drawing.size(368, 144);
this.datagrid1.tabindex = 0;
this.datagrid1.mousedown += new system.windows.forms.mouseeventhandler(this.datagrid1_mousedown);
//
// label1
//
this.label1.location = new system.drawing.point(4, 166);
this.label1.name = "label1";
this.label1.size = new system.drawing.size(383, 23);
this.label1.tabindex = 1;
this.label1.textalign = system.drawing.contentalignment.middlecenter;
this.label1.click += new system.eventhandler(this.form1_click);
//
// form1
//
this.autoscalebasesize = new system.drawing.size(5, 13);
this.clientsize = new system.drawing.size(387, 201);
this.controls.addrange(new system.windows.forms.control[] {
this.label1,
this.datagrid1});
this.name = "form1";
this.text = "鼠標雙擊事件的例子";
((system.componentmodel.isupportinitialize)(this.datagrid1)).endinit();
this.resumelayout(false);

}
#endregion

[stathread]
static void main()
{
application.run(new form1());
}

private void textboxdoubleclickhandler(object sender, eventargs e)
{
messagebox.show("雙擊事件發生。鼠標雙擊到的值:"+((textbox)sender).text.tostring());
}

private void textboxmousedownhandler(object sender, mouseeventargs e)
{
if(datetime.now < gridmousedowntime.addmilliseconds(systeminformation.doubleclicktime))
{
messagebox.show("雙擊事件發生。鼠標雙擊到的值:"+((textbox)sender).text.tostring());
}
label1.text = "textbox 鼠標按下了。 ";
}

private void datagrid1_mousedown(object sender, system.windows.forms.mouseeventargs e)
{
gridmousedowntime = datetime.now;
label1.text = "datagrid1 鼠標按下了。 ";
}

private void form1_click(object sender, system.eventargs e)
{
label1.text="";
}
private void label1_click(object sender, system.eventargs e)
{
label1.text="";
}
}
}



國內最大的酷站演示中心!
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 始兴县| 胶南市| 潮州市| 河北区| 海门市| 湘西| 越西县| 曲周县| 嫩江县| 开平市| 丰宁| 宣汉县| 娄底市| 濮阳县| 乌审旗| 杂多县| 新邵县| 南城县| 绥江县| 大庆市| 泽州县| 元谋县| 江西省| 庐江县| 社会| 万安县| 石阡县| 沙河市| 金堂县| 腾冲县| 新密市| 城步| 陇西县| 永川市| 长岭县| 崇左市| 图木舒克市| 襄汾县| 武隆县| 云浮市| 丁青县|