Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to Select Rows via the Mouse

$
0
0

This example demonstrates how to select rows by simply moving the mouse over them with the mouse button pressed

Question Comments

Added By: Daniel Kaminski at: 8/14/2015 6:46:32 AM    

Thanks for the example. Here is the code that will do the same for columns. You could post it for others to use if you like

   Private m_nStartColumn As Integer = -1
   Private m_nCurrColumn As Integer = -1
   ''' <summary>
   ''' ** Columnn selection
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub gvJob_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles gvJob.MouseDown
       Dim view As GridView = TryCast(sender, GridView)
       m_nStartColumn = GetColumnAt(TryCast(sender, GridView), e.X, e.Y)
   End Sub
   Private Sub gvJob_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gvJob.MouseMove
       Dim nCol As Integer = GetColumnAt(TryCast(sender, GridView), e.X, e.Y)
       If m_nCurrColumn <> nCol AndAlso nCol > -1 Then
           m_nCurrColumn = nCol
           SelectColumns(TryCast(sender, GridView), m_nStartColumn, m_nCurrColumn)
       End If
   End Sub
   Private Sub gvJob_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gvJob.MouseUp
       m_nStartColumn = -1
       m_nCurrColumn = -1
   End Sub
   Private Function GetColumnAt(ByVal view As GridView, ByVal x As Integer, ByVal y As Integer) As Integer
       Dim hi As GridHitInfo = view.CalcHitInfo(New Point(x, y))
       'If hi.Column.Visible = false
       If hi.InColumn AndAlso hi.Column.Visible Then Return hi.Column.AbsoluteIndex
       Return -1
   End Function
   Private Sub SelectColumns(ByVal view As GridView, ByVal nStartCol As Integer, ByVal nEndCol As Integer)
       If nStartCol > -1 AndAlso nEndCol > -1 Then
           view.BeginSelection()
           view.ClearSelection()
           Dim nStep As Integer = 1
           If nStartCol > nEndCol Then nStep = -1
           For nCol As Integer = nStartCol To nEndCol Step nStep
               SelectCells(view, nCol)
               'Debug.WriteLine("Selected Col {0}", nCol)
           Next
           view.EndSelection()
           view.Invalidate()
       End If
   End Sub
   Private Sub SelectCells(ByVal view As GridView, ByVal nCol As Integer)
       Dim gc As GridColumn = view.Columns(nCol)
       For i As Integer = 0 To view.RowCount - 1
           view.SelectCell(i, gc)
       Next i
   End Sub


Viewing all articles
Browse latest Browse all 7205

Trending Articles