Solved

MultiSelect DataGridView

Posted on 2010-09-11
6
677 Views
Last Modified: 2012-05-10
This is a 2 part question

First Part

I have a multi-select datagridview that has 2 columns.  I need to read the two columns of each selected item into an arraylist.  

Part 2

Can I create a Property typed as an ArrayList and save the ArrayList to that Property?



0
Comment
Question by:sherbug1015
[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
  • 4
  • 2
6 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33654260
try this

        Dim ArrList As ArrayList = New ArrayList()
        Dim i As Integer = 0
        Dim Col as integer
        
        For i = 0 To Me.dataGridView1.SelectedRows.Count
            ArrayList.Insert(0, Me.dataGridView1.SelectedRows(i))

        Next

Open in new window

0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33654267
This is for one column ...You should add one more loop
For Col=0 to Me.DatagridView.Column.Count-1  

Next
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33654272
Also you have to set MultiSelect Propertyto true
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:sherbug1015
ID: 33654425
I am trying your solution, but I must be doing something wrong.

First I fill the datagridview with values

Then while holding down the Shift key I pick a couple of rows

Then I have a button and the click event code is

Dim ncount As Integer
        ncount = Me.DataGridView1.SelectedRows.Count
        MsgBox(ncount)

The MsgBox value is always 0 no matter how many rows I select

Any ideas why SelectedRows won't return a value?

Thanks
0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 33654456
You have to set selectionMode FullRowSelect,And Multiselect to true
0
 

Author Comment

by:sherbug1015
ID: 33654504
OK.  I didn't know about the FullRowSelect.  Thanks a bunch.  
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

624 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