Solved

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

Posted on 2008-06-23
5
1,501 Views
Last Modified: 2008-06-23
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
Comment
Question by:htabbach
  • 3
  • 2
5 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 21850815
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
 

Author Comment

by:htabbach
ID: 21850840
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
 
LVL 48

Expert Comment

by:jpaulino
ID: 21850850
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
 

Author Comment

by:htabbach
ID: 21850857
yes
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 21850909
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now