Solved

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

Posted on 2010-09-21
8
963 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
  • 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
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33726516
see my first comment....you can do that ...
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now