EDN Admin
Well-known member
I am trying to populate a listview from datable with the code below.
But when a row is null, the program brings up an error that row cannot be DBNULL, can someone please help with this?
Private Sub ShowDataInLvw(ByVal data As DataTable, ByVal lvw As ListView)<br/>
lvw.View = View.Details<br/>
lvw.GridLines = True<br/>
lvw.Columns.Clear()<br/>
lvw.Items.Clear()<br/>
For Each col As DataColumn In data.Columns<br/>
lvw.Columns.Add(col.ToString)<br/>
Next<br/>
For Each row As DataRow In data.Rows<br/>
Dim lst As ListViewItem<br/>
lst = lvw.Items.Add(row(0))<br/>
For i As Integer = 1 To data.Columns.Count - 1<br/>
lst.SubItems.Add(row(i))<br/>
Next<br/>
Next<br/>
End Sub
View the full article
But when a row is null, the program brings up an error that row cannot be DBNULL, can someone please help with this?
Private Sub ShowDataInLvw(ByVal data As DataTable, ByVal lvw As ListView)<br/>
lvw.View = View.Details<br/>
lvw.GridLines = True<br/>
lvw.Columns.Clear()<br/>
lvw.Items.Clear()<br/>
For Each col As DataColumn In data.Columns<br/>
lvw.Columns.Add(col.ToString)<br/>
Next<br/>
For Each row As DataRow In data.Rows<br/>
Dim lst As ListViewItem<br/>
lst = lvw.Items.Add(row(0))<br/>
For i As Integer = 1 To data.Columns.Count - 1<br/>
lst.SubItems.Add(row(i))<br/>
Next<br/>
Next<br/>
End Sub
View the full article