Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Multiple row selection using shift+mouse down on datagridview+windows programming vb.net 2005

Posted on 2010-09-21
8
Medium Priority
?
1,040 Views
Last Modified: 2012-05-10
Hi,
I need to do Multiple row selection using shift+mouse down on datagridview.How can I achieve this?I have cell formatting event on grid to set the backcolor and forecolor of the row.

Cheers
0
Comment
Question by:RIAS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33726390
set the selection mode to full row select...and check multiselect =true
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33726466
with my comment above you canmake a multiselection with shift and mouse ...(continiously selection)..i do not understand about cell formatting ..what do you want to achieve?
0
 

Author Comment

by:RIAS
ID: 33726474
Sorry misleading question.I need to do shift+mousedown to select one row and still holding the shift key down select another row.Find the range and then select all
0
Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33726516
see my first comment....you can do that ...
0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 2000 total points
ID: 33726555
try this
 Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
        
        Dim Sval As Integer = Me.DataGridView1.SelectedRows.Count
        Me.TextBox1.Text = Sval
    End Sub

Open in new window

0
 

Author Comment

by:RIAS
ID: 33732555
Hi,
What I am doing here is setting a flag true if  shift key is hit with mouse down.Now I need to capture the rowindex on mouse capture event  i.e selection from and again rowindex i.e selection to .
Any suggestions on how to find these 2 indexes ?
0
 

Author Comment

by:RIAS
ID: 33732695
Hi,
Here is the code:

Private Sub Dg4_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles Dg4.CellMouseClick
If e.RowIndex = -1 Then Exit Sub
Dim intRowindexTo As Object = Nothing 'store the row index of the grid to select to 'shift key multiple select
If flgMultiSelectionShiftKey = True AndAlso e.ColumnIndex <> 5 AndAlso flgDone = False Then
intRowindexFrom = e.RowIndex
flgDone = True
flgMultiSelectionShiftKey = False
Exit Sub
 
ElseIf flgMultiSelectionShiftKey = True AndAlso e.ColumnIndex <> 5 AndAlso flgDone = True Then
flgDone = False
intRowindexTo = e.RowIndex
Dim i As Integer
If intRowindexFrom < intRowindexTo Then
For i = intRowindexFrom To intRowindexTo
 
 
Dim cbxCell As DataGridViewTextBoxCell
cbxCell = Dg4.Rows(i).Cells(0)
If IsDBNull(cbxCell.Value) = True Then
cbxCell.Value = True
If DictionaryRowNumber.ContainsKey(i) = False Then DictionaryRowNumber.Add(i, DictionaryRowNumber.Count)
ElseIf cbxCell.Value = "False" Then
cbxCell.Value = True
If DictionaryRowNumber.ContainsKey(i) = False Then DictionaryRowNumber.Add(i, DictionaryRowNumber.Count)
ElseIf cbxCell.Value = "True" AndAlso sender.CurrentCell.ColumnIndex <> 5 Then
End If
If sender.SelectedRows.count > 1 Then
flgMultiselect = True
Else
flgMultiselect = False
End If
 
Next
End If
intRowindexFrom = Nothing
flgDone = False
flgMultiSelectionShiftKey = False
End If
End Sub
 
Cheers mate
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33732876
you can find the row index of the first selected row and  then add the select.Count Rows
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question