Solved

Datagridview, selected rows -> transferring to list box

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

628 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