2022年7月19日 星期二

HOW TO CONVERT OF LISTVIEW TO DATATABLE IN VB.NET

參考來源

---

 Public for Function CONVRSION_LISTVIEW_TO_DATATABLE(ByVal LS_VIEW As ListView) As DataTable

'LS_VIEW.Items.Clear()

Dim DT_TAB As New DataTable

If LS_VIEW.Items.Count < 1 Then

Return DT_TAB

Else

For i As Integer = 0 To LS_VIEW.Items(0).SubItems.Count - 1

Dim DCOL As New DataColumn(LS_VIEW.Columns(i).Text)

DT_TAB.Columns.Add(DCOL)

Next

End If

For i As Integer = 0 To LS_VIEW.Items.Count - 1

Dim DROW As DataRow = DT_TAB.NewRow

For j As Integer = 0 To LS_VIEW.Items(i).SubItems.Count - 1

DROW(LS_VIEW.Columns(j).Text) = LS_VIEW.Items(i).SubItems(j).Text

Next

DT_TAB.Rows.Add(DROW)

Next

Return DT_TAB

End Function

沒有留言:

張貼留言