Solved

Datagridview, selected rows -> transferring to list box

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 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