Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-06-28
3
Medium Priority
?
255 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

597 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