Private Function saveToDataTable(ByVal lbxListBox As ListBox, ByVal TableName As String, ByVal ValueField As String, ByVal TextField As String) As Data.DataTable
Dim dtTable As New Data.DataTable(TableName)
Dim dcId As Data.DataColumn = New Data.DataColumn(ValueField, Type.GetType("System.Int32"))
Dim dcName As Data.DataColumn = New Data.DataColumn(TextField, Type.GetType("System.String"))
dtTable.Columns.Add(dcId)
dtTable.Columns.Add(dcName)
Dim drNewRow As Data.DataRow
For Each liListItem As ListItem In lbxListBox.Items
drNewRow = dtTable.NewRow
drNewRow(dcId) = liListItem.Value
drNewRow(dcName) = liListItem.Text
dtTable.Rows.Add(drNewRow)
Next
Return dtTable
End Function
|