Solved DataGridView get just row indexes of cells selected

Posted on 2014-07-11
1 Endorsement
Last Modified: 2014-07-15

I often need to loop through the row indexes of cells selected in a DataGridView
without looping through every cell
Is there a way to loop through just the unique rows selected?
Question by:murbro
    LVL 35

    Accepted Solution

    Just some code to help you along the way (I hope).
            Dim myUniqueList As List(Of Integer)
            myUniqueList = New List(Of Integer)
            For counter = 0 To (DataGridView1.SelectedCells.Count - 1)
                If Not myUniqueList.Contains(DataGridView1.SelectedCells(counter).RowIndex) Then myUniqueList.Add(DataGridView1.SelectedCells(counter).RowIndex)
            For Each uniques In myUniqueList

    Open in new window

    LVL 83

    Expert Comment

    Does looping through the DataGridView.SelectedRows collection not work?

    Author Comment

    No. I have tried that

    Author Closing Comment


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    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…
    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…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    755 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

    16 Experts available now in Live!

    Get 1:1 Help Now