zoukankan      html  css  js  c++  java
  • 按住Ctrl可选择多行的DataGrid

    Public Class MyDataGrid
        
    Inherits DataGrid

        
    Private selectedIndices As New ArrayList

        
    Public ReadOnly Property MultiSelectedIndices() As Integer()
            
    Get
                
    Return selectedIndices.ToArray(GetType(Integer))
            
    End Get
        
    End Property

        
    Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
            
    Dim info As DataGrid.HitTestInfo = HitTest(e.X, e.Y)
            
    If HitDataGrid(info) Then
                
    MyBase.OnMouseDown(e)
            
    End If
        
    End Sub

        
    Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
            
    MyBase.OnMouseUp(e)

            
    Dim info As DataGrid.HitTestInfo = HitTest(e.X, e.Y)
            
    If info.Type = HitTestType.Cell Then
                
    If selectedIndices.Count = 0 Then
                    
    Me.Select(info.Row)
                
    End If
            
    End If
        
    End Sub

        
    Private Function HitDataGrid(ByVal info As DataGrid.HitTestInfo) As Boolean
            
    Try
                
    Select Case Control.ModifierKeys
                    
    Case Keys.Control
                        
    If info.Row > -1 Then
                            
    If selectedIndices.IndexOf(info.Row) > -1 Then
                                selectedIndices.Remove(info.Row)
                                
    Me.UnSelect(info.Row)
                            
    Else
                                selectedIndices.Add(info.Row)
                                
    Me.Select(info.Row)
                            
    End If
                        
    End If
                        
    Return False
                    
    Case Keys.Shift
                        
    If info.Row > -1 Then
                            
    For Each IndexOld As Integer In selectedIndices
                                
    Me.UnSelect(IndexOld)
                            
    Next
                            selectedIndices.Clear()
                            
    Dim i, intStep As Integer
                            
    If info.Row > Me.CurrentRowIndex Then
                                intStep 
    = 1
                            
    Else
                                intStep 
    = -1
                            
    End If
                            
    For i = Me.CurrentRowIndex To info.Row Step intStep
                                selectedIndices.Add(i)
                                
    Me.Select(i)
                            
    Next
                        
    End If
                        
    Return False
                    
    Case Else
                        
    For Each index As Integer In selectedIndices
                            
    Me.UnSelect(index)
                        
    Next
                        selectedIndices.Clear()
                        
    If info.Type = DataGrid.HitTestType.RowHeader Then
                            selectedIndices.Add(info.Row)
                        
    End If
                        
    Return True
                
    End Select
            
    Catch ex As Exception
                Debug.WriteLine(ex.ToString)
            
    End Try
        
    End Function

    End Class
  • 相关阅读:
    获取页面元素的xpath,验证自己写的xpath,不用工具不用插件,看完这篇保证你学会!
    Python判断IEDriverServer是否最新版本并自动更新
    Python判断软件版本号的大小
    selenium通过加载火狐Firefox配置文件FirefoxProfile,实现免登陆访问网站
    mysql查询每个学生的各科成绩,以及总分和平均分
    selenium点击(click)页面元素没有反应(报element not interactable)的一个案例
    Python查询物理主机上所有虚拟机并保存为excel,通过标记批量启动
    Python线程池下载txt
    Python自动下载最新的chromedriver
    django的url的name参数的意义
  • 原文地址:https://www.cnblogs.com/LeoWong/p/1357115.html
Copyright © 2011-2022 走看看