Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ListView1.Items.Clear() ' Create the column headers. ListView1.Columns.Add("Id", 10, HorizontalAlignment.Left) ListView1.Columns.Add("Word", 10, HorizontalAlignment.Left) ListView1.Columns.Add("Meaning", 10, HorizontalAlignment.Left) ListView1.Columns.Add("Gujarati", 10, HorizontalAlignment.Left) ListView1.Columns.Add("Syn", 10, HorizontalAlignment.Right) ListView1.Columns.Add("Ant", 10, HorizontalAlignment.Left) ' Start with details view. Dim cn As SqlConnection = GetDbConnection() ' Select records. Dim cmd As New SqlCommand("select * from Dictionary", cn) Dim data_reader As SqlDataReader = cmd.ExecuteReader() 'data_reader = cmd.ExecuteReader() Do While data_reader.Read() Dim new_item As New ListViewItem(data_reader.Item("Id").ToString) new_item.SubItems.Add(data_reader.Item("Word").ToString) new_item.SubItems.Add(data_reader.Item("Meaning").ToString) new_item.SubItems.Add(data_reader.Item("Gujarati").ToString) new_item.SubItems.Add(data_reader.Item("Syn").ToString) new_item.SubItems.Add(data_reader.Item("Ant").ToString) ListView1.Items.Add(new_item) Debug.WriteLine(new_item.Text & " : " & _ new_item.SubItems(0).Text & ", " & _ new_item.SubItems(1).Text & ", " & _ new_item.SubItems(2).Text & ", " & _ new_item.SubItems(3).Text & ", " & _ new_item.SubItems(4).Text) Loop 'Dim wid As Integer 'For i As Integer = 0 To ListView1.Columns.Count - 1 ' ListView1.Columns(i).Width = -2 ' wid += ListView1.Columns(i).Width 'Next i 'Me.ClientSize = New Size(wid + 20, Me.ClientSize.Height) End Sub Private Function GetDbConnection() As SqlConnection ' Compose the connect string. Dim cn As New SqlConnection("Data Source=SANJAY-26EEFF19\SQLEXPRESS;Initial Catalog=Dict;Integrated Security=True") ' Open a database connection. cn.Open() ' Return the connection. Return cn End Function
dim dt as datatable 'fill datatable here listview1.datasource = dt
Dim cn As New SqlConnection("Data Source=SANJAY-26EEFF19\SQLEXPRESS;Initial Catalog=Dict;Integrated Security=True")
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)