Solved

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

Posted on 2010-09-21
8
1,007 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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