Solved

Datagridview, selected rows -> transferring to list box

Posted on 2006-11-03
3
2,350 Views
Last Modified: 2010-08-05
I have a datagridview where the user can select multiple rows.  As the user is selecting the rows I want the first column to display in a listbox.  How would I go about this.  My attempt so far (which doesn't work):

    Private Sub DataGridView1_Mouseup(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseUp

        Dim selected As New ArrayList()

        Dim row As DataRow <-- it says that Datrow is not compatible with datagridview selected rows

        For Each row In DataGridView1.SelectedRows
            selected.Add(DataGridView1.SelectedRows.Item("name"))
        Next

        ListBox1.DataSource = selected

    End Sub
0
Comment
Question by:DavidGreenfield
3 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 17868298
Try this

        Dim selected As New ArrayList()

        Dim row As DataGridViewRow

        For Each row In DataGridView1.SelectedRows
            selected.Add(row.Cells("Name").Value)
        Next

        ListBox1.DataSource = selected

Roger
0
 

Author Comment

by:DavidGreenfield
ID: 17868330
Bonza! Thank you very much Roger!
0
 

Expert Comment

by:delphiuser2009
ID: 32903089
@Sancler:

I know it's been a while since the solution of this topic, but I do have a small question.

Your code seems to work well, only when I select one row at the time and try to add it to the listbox, it overrides the previous inserted item.

How to solve this?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

22 Experts available now in Live!

Get 1:1 Help Now