Solved

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

Posted on 2010-09-21
8
959 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
Comment Utility
set the selection mode to full row select...and check multiselect =true
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
Comment Utility
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
Comment Utility
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
Comment Utility
see my first comment....you can do that ...
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
you can find the row index of the first selected row and  then add the select.Count Rows
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

9 Experts available now in Live!

Get 1:1 Help Now