首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

VB.net中winForm的dataGrid怎么只能选择单行

2012-01-08 
VB.net中winForm的dataGrid如何只能选择单行VB.net中winForm的dataGrid如何只能选择单行[解决办法]VB版,写

VB.net中winForm的dataGrid如何只能选择单行
VB.net中winForm的dataGrid如何只能选择单行

[解决办法]
VB版,写到一个类文件中就能用了。

Option Strict Off
Option Explicit On

Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Windows.Forms


Public Class MyDataGrid
Inherits DataGrid
Private oldSelectedRow As Integer
'Fields
'Constructors
'Events
'Methods
Public Sub New()
'Warning: Implementation not found
End Sub
Protected Overloads Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)

'don 't call the base class if left mouse down
If (e.Button <> Windows.Forms.MouseButtons.Left) Then
MyBase.OnMouseMove(e)
End If

End Sub
Protected Overloads Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)

'don 't call the base class if in header
Dim hti As DataGrid.HitTestInfo
hti = Me.HitTest(New Point(e.X, e.Y))
If (hti.Type = DataGrid.HitTestType.Cell) Then
If (oldSelectedRow > -(1)) Then
Me.UnSelect(oldSelectedRow)
End If
oldSelectedRow = -(1)
MyBase.OnMouseDown(e)
Else
If (hti.Type = DataGrid.HitTestType.RowHeader) Then
If (oldSelectedRow > -(1)) Then
Me.UnSelect(oldSelectedRow)
End If
If ((Control.ModifierKeys And Keys.Shift) _
= 0) Then
MyBase.OnMouseDown(e)
Else
Me.CurrentCell = New DataGridCell(hti.Row, hti.Column)
End If
Me.Select(hti.Row)
oldSelectedRow = hti.Row
End If
End If

End Sub
End Class

热点排行