troubleshooting Question

Datagridview only showing last row's data

Avatar of Darwin Johnson
Darwin JohnsonFlag for United States of America asked on
.NET ProgrammingVisual Basic.NET
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
                    .Rows.Add()
                End With
            End If
            intRow += 1
        NextDatgridview Last Row Only
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
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