Solved

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

Posted on 2008-06-23
5
1,504 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.

737 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