Here is the link to the page that I took the example from.
http://www.codeguru.com/vb/controls...icle.php/c3979/
I am using the last code example at the bottom of the page.
Here is the code I have:
VB Code:
Public Class clsLoadListView Dim myFM As New frmMain Dim ds As New DataSet Dim myData As OdbcDataReader Public Sub loadSelections(ByVal SelectBy As String) Dim building As Integer Dim sql As String Dim lvwColumn As ColumnHeader Dim itmListItem As ListViewItem = New ListViewItem Dim strtest As String Dim shtCntr As Short building = 11 '----fill in the field list Try myFM.dbconn.Open() Select Case SelectBy Case "Students" sql = "select studentid, studentname from reg where studentid = 18197 and building = " & building myFM.cmd = New OdbcCommand(sql, myFM.dbconn) myFM.cmd.CommandType = CommandType.Text myData = myFM.cmd.ExecuteReader myFM.lvwFields.Clear() For shtCntr = 0 To myData.FieldCount() - 1 lvwColumn = New ColumnHeader lvwColumn.Text = myData.GetName(shtCntr) myFM.lvwFields.Columns.Add(lvwColumn) Next Do While myData.Read itmListItem = New ListViewItem itmListItem.Text = myData(0) For shtCntr = 1 To myData.FieldCount() - 1 If myData.IsDBNull(shtCntr) Then itmListItem.SubItems.Add("") Else itmListItem.SubItems.Add(myData.GetString(shtCntr).Trim) End If Next shtCntr myFM.lvwFields.Items.Add(itmListItem) Loop End Select Catch ex As Exception MessageBox.Show("Error Reading Data. " & ex.Message) Finally myFM.dbconn.Close() lvwColumn = Nothing End Try End Sub




Reply With Quote