Solved

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

Posted on 2008-06-23
5
1,495 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
yes
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

12 Experts available now in Live!

Get 1:1 Help Now