Avatar of sherbug1015
sherbug1015
Flag for United States of America asked on

MultiSelect DataGridView

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?



Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
sherbug1015

8/22/2022 - Mon
John (Yiannis) Toutountzoglou

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

John (Yiannis) Toutountzoglou

This is for one column ...You should add one more loop
For Col=0 to Me.DatagridView.Column.Count-1  

Next
John (Yiannis) Toutountzoglou

Also you have to set MultiSelect Propertyto true
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
sherbug1015

ASKER
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
ASKER CERTIFIED SOLUTION
John (Yiannis) Toutountzoglou

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
sherbug1015

ASKER
OK.  I didn't know about the FullRowSelect.  Thanks a bunch.