Listview assign database but how to adjust column width

  • Thread starter Thread starter muhammadanzar
  • Start date Start date
M

muhammadanzar

Guest
hi,

I want to show the database values in list view, but when it show the column are shrink. i want column are according to data base value hader.

my code is given below

Imports System.Data.SqlClient
Public Class Form2
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim itemcoll(100) As String


Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ListView1.View = View.Details
Me.ListView1.GridLines = True

Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True")

Dim strQ As String = String.Empty

strQ = "SELECT Pid,Remarks,PreviousBalance,CashPaid,Remain,CustomerName,EmployeeNaame FROM dbo.PaymentReceived"

cmd = New SqlCommand(strQ, conn)
da = New SqlDataAdapter(cmd)
ds = New DataSet
da.Fill(ds, "Table")

Dim i As Integer = 0
Dim j As Integer = 0

' adding the columns in ListView
For i = 0 To ds.Tables(0).Columns.Count - 1
Me.ListView1.Columns.Add(ds.Tables(0).Columns(i).ColumnName.ToString())
Next


'Now adding the Items in Listview
For i = 0 To ds.Tables(0).Rows.Count - 1

For j = 0 To ds.Tables(0).Columns.Count - 1

itemcoll(j) = ds.Tables(0).Rows(i)(j).ToString()
Next
Dim lvi As New ListViewItem(itemcoll)
Me.ListView1.Items.Add(lvi)
Me.ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)

Next
End Sub
End Class




MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959

Continue reading...
 
Back
Top