Solved

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

Posted on 2010-09-21
8
975 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

837 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