<!
StartFragment
>Option Strict Off
Option Explicit On
Imports Microsoft
VisualBasic
Imports System
Imports System
ComponentModel
Imports System
Data
Imports System
Drawing
Imports System
<a _blank
>Windows</a>
Forms
Namespace <a _blank
>DataGrid</a>DoubleClick
Public Class Form
Inherits Form
Private WithEvents dataGrid
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()
dataGrid
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 newRow
As DataRow
Dim i As Integer
i =
Do While (i <
)
newRow
= tCust
NewRow
newRow
(
custID
) = i
ToString()
tCust
Rows
Add(newRow
)
i = (i +
)
Loop
tCust
Rows(
)(
custName
) =
【孟憲會之精彩世界】
tCust
Rows(
)(
custName
) =
net_lover
tCust
Rows(
)(
custName
) = //<a _blank
>XML</a>
sz
luohuedu<a _blank
&</a>/
tCust
Rows(
)(
custCity
) =
北京
tCust
Rows(
)(
custCity
) =
上海
tCust
Rows(
)(
custCity
) =
河南
End Sub
Private Sub AddCustomDataTableStyle()
Dim ts
As DataGridTableStyle
ts
= New DataGridTableStyle()
ts
MappingName =
Customers
ts
AlternatingBackColor = Color
LightGray
Dim TextCol As DataGridTextBoxColumn
TextCol = New DataGridTextBoxColumn()
TextCol
MappingName =
custID
TextCol
HeaderText =
序號
TextCol
Width =
AddHandler TextCol
TextBox
MouseDown
New MouseEventHandler(AddressOf TextBoxMouseDownHandler)
AddHandler TextCol
TextBox
DoubleClick
New EventHandler(AddressOf TextBoxDoubleClickHandler)
ts
GridColumnStyles
Add(TextCol)
TextCol = New DataGridTextBoxColumn()
TextCol
MappingName =
custName
TextCol
HeaderText =
姓名
TextCol
Width =
AddHandler TextCol
TextBox
MouseDown
New MouseEventHandler(AddressOf TextBoxMouseDownHandler)
AddHandler TextCol
TextBox
DoubleClick
New EventHandler(AddressOf TextBoxDoubleClickHandler)
ts
GridColumnStyles
Add(TextCol)
TextCol = New DataGridTextBoxColumn()
TextCol
MappingName =
custCity
TextCol
HeaderText =
地址
TextCol
Width =
AddHandler TextCol
TextBox
MouseDown
New MouseEventHandler(AddressOf TextBoxMouseDownHandler)
AddHandler TextCol
TextBox
DoubleClick
New EventHandler(AddressOf TextBoxDoubleClickHandler)
ts
GridColumnStyles
Add(TextCol)
dataGrid
TableStyles
Add(ts
)
End Sub
Friend WithEvents Label
As System
Windows
Forms
Label
Private Sub InitializeComponent()
Me
dataGrid
= New System
Windows
Forms
DataGrid()
Me
Label
= New System
Windows
Forms
Label()
CType(Me
dataGrid
System
ComponentModel
ISupportInitialize)
BeginInit()
Me
SuspendLayout()
dataGrid
Me
dataGrid
CaptionVisible = False
Me
dataGrid
DataMember =
Me
dataGrid
HeaderForeColor = System
Drawing
SystemColors
ControlText
Me
dataGrid
Location = New System
Drawing
Point(
)
Me
dataGrid
Name =
dataGrid
Me
dataGrid
Size = New System
Drawing
Size(
)
Me
dataGrid
TabIndex =
Label
Me
Label
Location = New System
Drawing
Point(
)
Me
Label
Name =
Label
Me
Label
Size = New System
Drawing
Size(
)
Me
Label
TabIndex =
Me
Label
TextAlign = System
Drawing
ContentAlignment
MiddleCenter
Form
Me
AutoScaleBaseSize = New System
Drawing
Size(
)
Me
ClientSize = New System
Drawing
Size(
)
Me
Controls
AddRange(New System
Windows
Forms
Control() {Me
Label
Me
dataGrid
})
Me
Name =
Form
Me
Text =
鼠標雙擊事件的例子
CType(Me
dataGrid
System
ComponentModel
ISupportInitialize)
EndInit()
Me
ResumeLayout(False)
End Sub
<STAThread()> _
Public Shared Sub Main()
Application
Run(New Form
())
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
Label
Text =
TextBoxMouseDownHandler
End Sub
Private Sub dataGrid
_MouseDown(ByVal sender As System
Object
_
ByVal e As System
Windows
Forms
MouseEventArgs) Handles dataGrid
MouseDown
gridMouseDownTime = DateTime
Now
Label
Text =
dataGrid
_MouseDown
End Sub
Private Sub Label
_Click(ByVal sender As System
Object
ByVal e As System
EventArgs) _
Handles Label
Click
Label
Text =
End Sub
Private Sub Form
_Click(ByVal sender As System
Object
ByVal e As System
EventArgs) _
Handles MyBase
Click
Label
Text =
End Sub
End Class
End Namespace
From:http://tw.wingwit.com/Article/program/net/201311/11554.html