动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   .Net → 阅读文章

 .net datagrid 选择多行

作者:郁郁小蝎 来源:中国站长学院 
阅读 3093 人次 , 2006-2-15 14:31:00 

  功能:点击datagrid并且按住键盘上的ctrl或shift可选择多行

Public Class MyDataGridCLASS
    Inherits DataGrid
    Private m As New ArrayList

    Public ReadOnly Property MultiSelectedIndex() As Integer()
        Get
            Return m.ToArray(GetType(Integer))
        End Get
    End Property

    Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
        Debug.WriteLine("DataGrid has hit")
        Dim posdg As Point = New Point(e.X, e.Y)
        Dim hitDG As DataGrid.HitTestInfo = HitTest(posdg)
        If HitDataGrid(hitDG) Then
            MyBase.OnMouseDown(e)
            Debug.WriteLine("Mousedown has gogogo.....")
        End If
    End Sub

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

  
 本文Tagstag  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:用控件仅一条指令实现界面换肤和多语言版本
· 下一篇:一个用C#写的词法分析程序
· .Net里一个用于驱动摄像头的类
· asp+中是如何连接数据库ado+的
· 为按钮添加 确认 对话框
· .net 里面 protected private 的变量也可以访问
· javamail在jsp中调用 二


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077