Solved

Datagridview, selected rows -> transferring to list box

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

756 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