Good, I would like you to help me, I'm doing a Listview that as default I put these values in the columns:
Credit Number
Quota Number
Last Fee
Item
but I want those list view to increase the number of columns as the database has in its fields My table is called item has this unique field: . Description But inside as a record you have these data: . INSURANCE HOSPITAL ASSISTANCE . SAFEGUARD INSURANCE
What I want to see in the list view with those columns of the records in the database like this: . Credit Number
Quota Number
Last Fee
Item
INSURANCE HOSPITAL ASSISTANCE
SAFEGUARD INSURANCE
This is my code that I made but if it shows but it shows up as records I want as columns this is my code:
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.ListView1.View = View.Details Me.ListView1.GridLines = True conn = New SqlConnection("Data Source=********\SQL2012;Initial Catalog=Credito;User ID=****;Password=*****") Dim strQ As String = String.Empty strQ = "select top 5 Descripcion from credito..Rubro WHERE IdRubro NOT IN (41,42,44,45,1056,1057,1058,48,43) " cmd = New SqlCommand(strQ, conn) da = New SqlDataAdapter(cmd) ds = New DataSet da.Fill(ds, "Rubros") 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) Next End Sub
This is with this code I get the error: