Solved

Datagridview, selected rows -> transferring to list box

Posted on 2006-11-03
3
2,319 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

13 Experts available now in Live!

Get 1:1 Help Now