Adding a Row to an Unbound DataGridView ??

Tech-Archive recommends: Fix windows errors by optimizing your registry



I am using a DataGridView, unbound, for the first time and am unable to add
a row. My add a row code looks like this ...

Sub AddRow(ByRef dirname As String, ByRef filename As String, ByRef length
As Long, _
ByRef lat As Date)

Dim RowData As New CRowData

With RowData
.dirname = dirname
.filename = filename
.length = length
.lat = lat
End With

With Me.DataGridView1
.Rows.Add(RowData)
End With

End Sub 'AddRow

Class CRowData
Public dirname As String
Public filename As String
Public length As Long
Public lat As Date

End Class

A break after setting up RowData for the first row indicates that the right
data is in RowData. But only the first column is populated and it is set,
incorrectly, to "FlatView.Form1+CRowData".

In an earlier version of the code all columns were String and I successfully
used code like this ...

Dim row As String() = {"11/22/1968", "29", "Revolution 9", _
"Beatles", "The Beatles [White Album]"}

With Me.songsDataGridView.Rows
.Add(row)
End With

But then I discovered that my "length" column, as a String, was not sorting
properly. So I've made that column a Long, but now I can't figure out how
to add the row data. I found some doc indicating that Rows.Add() will take
an object but I must not completely understand how to do that.

I'll be grateful for any help. Thanks, Bob


.



Relevant Pages