-
Add Row DataGridView
I have a DataGridView item on my form, and when I add an item to it, it doesn't add an extra row to add new items.
Here is the code I use to load a file dialog box:
Code:
Private Sub Loader_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Loader.Click
If loadFile.ShowDialog Then
loadData(loadFile.FileName)
End If
End Sub
Once a file is chosen, I use the following to add it to the grid:
Code:
Private Sub loadData(ByVal fileLocation As String)
Dim fileName = GetFileNameWithoutExtension(fileLocation)
Dim outputLocation = System.IO.Path.GetDirectoryName(fileLocation)
Dim rowCount = Files.RowCount
Dim good = True
Dim i = rowCount - 1
Files.Item(1, i).Value = fileLocation
Files.Item(2, i).Value = outputLocation
Files.Item(3, i).Value = fileName
End Sub
It loads it to the gird, and doesn't automatically add a second empty row.
The only way for me to add another row, is by typing into one of the fields in the column, and it adds the next row for me.
How can I get it to add the other row without me having to type into the field?
If that doesn't make sense, please let me know!
Thanks for the Help!
-
Re: Add Row DataGridView
Of course it will do that since you have
Code:
Dim i = rowCount - 1
Which is the index of the last row on the DGV. If you want to add a new row, just do this
Code:
Private Sub loadData(ByVal fileLocation As String)
Dim fileName = GetFileNameWithoutExtension(fileLocation)
Dim outputLocation = System.IO.Path.GetDirectoryName(fileLocation)
Dim good = True
Files.Rows.Add(Nothing, fileLocation, outputLocation, fileName)
End Sub
And BTW, what's the purpose of declaring the boolean variable good if you're not using it anywhere?
-
Re: Add Row DataGridView