Option Strict Off Option Explicit On Imports Microsoft.VisualBasic Imports System Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Windows.Forms Namespace DataGridDoubleClick Public Class Form1 Inherits Form Private WithEvents dataGrid1 As DataGrid Private WithEvents myDataSet As DataSet Private gridMouseDownTime As DateTime Private components As Container Public Sub New() MyBase.New() InitializeComponent() gridMouseDownTime = DateTime.Now SetUp() End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If (Not (components) Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Private Sub SetUp() MakeDataSet() dataGrid1.SetDataBinding(myDataSet, "Customers") AddCustomDataTableStyle() End Sub Private Sub MakeDataSet() myDataSet = New DataSet("myDataSet") Dim tCust As DataTable tCust = New DataTable("Customers") Dim cCustID As DataColumn cCustID = New DataColumn("custID") Dim cCustName As DataColumn cCustName = New DataColumn("custName") Dim cCurrent As DataColumn cCurrent = New DataColumn("custCity") tCust.Columns.Add(cCustID) tCust.Columns.Add(cCustName) tCust.Columns.Add(cCurrent) myDataSet.Tables.Add(tCust) Dim newRow1 As DataRow Dim i As Integer i = 1 Do While (i < 4) newrow1 = tcust.newrow newrow1("custid") = i.tostring() tcust.rows.add(newrow1) i = (i + 1) loop 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") = "河南" end sub private sub addcustomdatatablestyle() dim ts1 as datagridtablestyle ts1 = new datagridtablestyle() ts1.mappingname = "customers" ts1.alternatingbackcolor = color.lightgray dim textcol as datagridtextboxcolumn textcol = new datagridtextboxcolumn() textcol.mappingname = "custid" textcol.headertext = "序号" textcol.width = 100 addhandler textcol.textbox.mousedown, new mouseeventhandler(addressof textboxmousedownhandler) addhandler textcol.textbox.doubleclick, new eventhandler(addressof textboxdoubleclickhandler) ts1.gridcolumnstyles.add(textcol) textcol = new datagridtextboxcolumn() textcol.mappingname = "custname" textcol.headertext = "姓名" textcol.width = 100 addhandler textcol.textbox.mousedown, new mouseeventhandler(addressof textboxmousedownhandler) addhandler textcol.textbox.doubleclick, new eventhandler(addressof textboxdoubleclickhandler) ts1.gridcolumnstyles.add(textcol) textcol = new datagridtextboxcolumn() textcol.mappingname = "custcity" textcol.headertext = "地址" textcol.width = 100 addhandler textcol.textbox.mousedown, new mouseeventhandler(addressof textboxmousedownhandler) addhandler textcol.textbox.doubleclick, new eventhandler(addressof textboxdoubleclickhandler) ts1.gridcolumnstyles.add(textcol) datagrid1.tablestyles.add(ts1) end sub friend withevents label1 as system.windows.forms.label private sub initializecomponent() me.datagrid1 = new system.windows.forms.datagrid() me.label1 = new system.windows.forms.label() ctype(me.datagrid1, system.componentmodel.isupportinitialize).begininit() me.suspendlayout() ' 'datagrid1 ' me.datagrid1.captionvisible = false me.datagrid1.datamember = "" me.datagrid1.headerforecolor = system.drawing.systemcolors.controltext me.datagrid1.location = new system.drawing.point(12, 8) me.datagrid1.name = "datagrid1" me.datagrid1.size = new system.drawing.size(368, 128) me.datagrid1.tabindex = 0 ' 'label1 ' me.label1.location = new system.drawing.point(10, 149) me.label1.name = "label1" me.label1.size = new system.drawing.size(370, 23) me.label1.tabindex = 1 me.label1.textalign = system.drawing.contentalignment.middlecenter ' 'form1 ' me.autoscalebasesize = new system.drawing.size(5, 13) me.clientsize = new system.drawing.size(388, 189) me.controls.addrange(new system.windows.forms.control() {me.label1, me.datagrid1}) me.name = "form1" me.text = "鼠标双击事件的例子" ctype(me.datagrid1, system.componentmodel.isupportinitialize).endinit() me.resumelayout(false) end sub _ Public Shared Sub Main() Application.Run(New Form1()) End Sub Private Sub TextBoxDoubleClickHandler(ByVal sender As Object, ByVal e As EventArgs) MessageBox.Show("TrueDoubleClick") End Sub Private Sub TextBoxMouseDownHandler(ByVal sender As Object, ByVal e As MouseEventArgs) If (DateTime.Now < gridmousedowntime.addmilliseconds(systeminformation.doubleclicktime)) then messagebox.show("griddoubleclick:" + ctype(sender, textbox).text) end if label1.text = "textboxmousedownhandler " end sub private sub datagrid1_mousedown(byval sender as system.object, _ byval e as system.windows.forms.mouseeventargs) handles datagrid1.mousedown gridmousedowntime = datetime.now label1.text = "datagrid1_mousedown " end sub private sub label1_click(byval sender as system.object, byval e as system.eventargs) _ handles label1.click label1.text = "" end sub private sub form1_click(byval sender as system.object, byval e as system.eventargs) _ handles mybase.click label1.text = "" end sub end class end namespace
【我对这篇文章有话说?】
广告位招租,广告代号:content_468_15
上一篇:如何得到资源文件中的文件 下一篇:从Window系统托盘控制Windows服务
- 关于我们 | 广告服务 | 网站建设 | 版权申明 | 申请链接 | 联系我们
- Copyright © 2007 5iaspx.COM. All Right Reserved.
- 本站内容仅供学习,研究,探讨,个人收藏,如有侵权,敬请联系我们,我们尽快解决!
|