troubleshooting Question

Datagridview only showing last row's data

Avatar of Darwin Johnson
Darwin JohnsonFlag for United States of America asked on
Visual Basic.NET.NET Programming
7 Comments1 Solution86 ViewsLast Modified:
I am trying to populate a datagridview from a datatable but I don't want to bind it to the datatable. With the below code it's only displaying data in the last row (see attached picture). There are 5 records in the table. When I single step through the code and watch the row count is changing and the data is changing.

        Dim CheckUser As DataTable, intRow As Integer = 0

        CheckUser = ReadDataFromDB("SELECT * FROM users;", False)

        For Each row In CheckUser.Rows

            If Not String.IsNullOrEmpty(row("UserID").ToString) Then
                'DGridVUsers.CurrentRow.Cells(0).Value = row("UserID").ToString
                ' DGridVUsers.Rows(intRow).Cells(0).Value = row("UserID").ToString
                With DGridVUsers
                    .Rows(.Rows.Count - 1).Cells("UserID").Value = row("UserID").ToString
                End With
            End If
            intRow += 1
        NextDatgridview Last Row Only
Freelance programmer / Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros