Solved

How do I Populate a ListView with the contents of a Dataset?

Posted on 2006-06-28
3
244 Views
Last Modified: 2006-11-18
Hi,

In my app I currently have a Dataset with one table full of data. I need to be able to programmatically transfer all that data to a listview. As the number of rows and columns in the dataset may change I need the code to be able to cope with this too. Any ideas?

Thanks.
0
Comment
Question by:kiranboi
[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
  • 2
3 Comments
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 17000001

        'I am creating a dummy DataTable here you might have your own code to get
        'the dataTable filled
        Dim DT As New DataTable
        DT.Columns.Add("Name", GetType(String))
        DT.Columns.Add("Age", GetType(Integer))
        DT.Columns.Add("Address", GetType(String))
        Dim Dr As DataRow
        For i As Integer = 1 To 5
            Dr = DT.NewRow
            Dr(0) = "Name " & CStr(i)
            Dr(1) = 10 * i
            Dr(2) = "Address " & CStr(i)
            DT.Rows.Add(Dr)
        Next


        '---Code to show data in ListView from the DataTable
        'Since we are not adding images the view woould be Details type
        LstView.View = View.Details
        'Now Add Columns and Headers to the List View
        For Each DC As DataColumn In DT.Columns
            LstView.Columns.Add(DC.ColumnName)
        Next
        'Now Add the Rows
        Dim Itm As ListViewItem
        For Each Dr In DT.Rows
            Itm = New ListViewItem(Dr(0).ToString)
            Itm.SubItems.Add(Dr(1))
            Itm.SubItems.Add(Dr(2))
            LstView.Items.Add(Itm)
        Next
0
 

Author Comment

by:kiranboi
ID: 17000027
Thats looking like the sort of thing i need. but instead of a datatable i have a dataset populated from an excel sheet. any chance of showing me the code i would need to use that. Thanks
0
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 500 total points
ID: 17000044
access the DataTable inside the Dataset like this YouDataSet.Tables(0)
so the code would change to

        LstView.View = View.Details
        For Each DC As DataColumn In YouDataSet.Tables(0).Columns '<-- Change the Dataset name here
            LstView.Columns.Add(DC.ColumnName)
        Next

        Dim Itm As ListViewItem
        For Each Dr In YouDataSet.Tables(0).Rows   '<-- Dataset name here
            Itm = New ListViewItem(Dr(0).ToString)
            Itm.SubItems.Add(Dr(1))
            Itm.SubItems.Add(Dr(2))
            LstView.Items.Add(Itm)
        Next
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

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