简体   繁体   中英

Adding new row at the end of DataGridView in vb.net

I'm using a for loop to list my .txt files item on DataGridView element but when i tested with a basic code i realize it's adding new rows from the top because of that only the last item listed on DataGridView.

 Public Shared Sub TestCode()
        For i = 0 To 6

            Me.DataGridView1.Rows(i).Cells(0).Value = "This is: " & i
            Me.DataGridView1.Rows.Insert(Me.DataGridView1.RowCount - 1)
            Me.DataGridView1.Update()
        Next
 End Sub

How is it possible to adding/inserting new rows at the bottom.

The last row in datagridview is to allow user to add row if he wants. Set DataGridView1.AllowUserToAddRows = False

Then try to use Me.DataGridView1.Rows.Add() . It will add a new row at the end of the dataGridView

or

try this dataGridView1.Rows.Insert(dataGridView1.Rows.Count-1, row);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM