Solved Add DataGridView row after the last

Posted on 2014-08-16
Last Modified: 2014-08-20
I a trying to add a DataGridView row after the last ro using the following code but it is adding it at the beginning before the first row

       Dim sTextDragged As String = DirectCast(e.Data.GetData(GetType(System.String)), System.String)
                Dim oNewRow As New DataGridViewRow
                oNewRow.Cells(0).Value = "Joined"
                oNewRow.Cells(1).Value = sTextDragged
                oNewRow.Cells(2).Value = "<none>"
                oNewRow.Cells(3).Value = "Joined"
                Me.DGV_Joins.Rows.Add(oNewRow) '
Question by:murbro
    LVL 96

    Expert Comment

    by:Bob Learned
    Is this a data-bound grid, or an unbound grid?

    Author Comment

    It is an unbound GridView
    LVL 96

    Expert Comment

    by:Bob Learned
    With an Unbound DataGridView, I prefer to use the VirtualMode, and then you can control the operations.

    Here is a description:

    Walkthrough: Implementing Virtual Mode in the Windows Forms DataGridView Control

    Author Comment

    Thanks Bob but I still just need a way to add a row at the end rather than the beginning
    LVL 96

    Accepted Solution

    In virtual mode, that would be RowCount + 1.  For non-virtual mode, try:

    dataGridView1.Rows.Insert(dataGridView1.Rows.Count - 1, row)

    Author Closing Comment

    Thanks very much

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    This video discusses moving either the default database or any database to a new volume.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 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

    15 Experts available now in Live!

    Get 1:1 Help Now