Solved

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

Posted on 2008-06-23
5
1,505 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

724 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