[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1511
  • Last Modified:

How can I populate a ListView control mnually from a datatable?

Hello,
I have a dattable that I would like to populate it into a ListView control, I tried everything I can with no luck. Please help!
0
htabbach
Asked:
htabbach
  • 3
  • 2
1 Solution
 
jpaulinoCommented:
This is just an example how to fill the listview from the dataset
       ' Fill the demo datatable
        Dim strNames() As String = {"George", "John", "Paul", "Andy", "Charles"}
        Dim dt As New DataTable
        dt.Columns.Add(New DataColumn("id", GetType(Integer)))
        dt.Columns.Add(New DataColumn("name", GetType(String))) 
        Dim dr As DataRow
        For x As Byte = 0 To strNames.Length - 1
            dr = dt.NewRow()
            dr.Item("id") = x.ToString
            dr.Item("name") = strNames(x).ToString
            dt.Rows.Add(dr)
        Next 
        ' Listview definitions
        Me.ListView1.View = View.Details
        Me.ListView1.GridLines = True
        Me.ListView1.FullRowSelect = True 
        ' Add the columns
        Me.ListView1.Columns.Add("ID")
        Me.ListView1.Columns.Add("Name") 
        
        'Fill the listview with information from the datatable
        Dim item As ListViewItem
        For Each mydr As DataRow In dt.Rows
            item = New ListViewItem
            item.Text = mydr(0).ToString
            item.SubItems.Add(mydr(1).ToString)
            Me.ListView1.Items.Add(item)
        Next

Open in new window

0
 
htabbachAuthor Commented:
Thank you for the response. The problem is that when I do listView. I don't get these properties that you included in the coe example, there is no Columns properties or View property
0
 
jpaulinoCommented:
I now check the zones you're added (NET, Programming for ASP.NET, Microsoft Visual Basic.Net). I only sow it .NET in the browser.

Is the listview for ASP.NET ?
0
 
htabbachAuthor Commented:
yes
0
 
jpaulinoCommented:
You can look on this links how to create the structure and the code. It's in C# but very easy to follow.
http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2007/05/23/asp-net-podcast-show-93-asp-net-listview-in-orcas-beta-1-video.aspx
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now