Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to retrieve data from database and display it in Listview

How to retrieve data from database and display it in Listview

Scheduled Pinned Locked Moved C#
databasehelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Edwin Syarief
    wrote on last edited by
    #1

    Hi, i got a problem with my application. Usually I retrieve data from database and display it in datagrid. But, how to display data in Listview. Thanx b4 Best Regards Edwin46 :)

    R N 2 Replies Last reply
    0
    • E Edwin Syarief

      Hi, i got a problem with my application. Usually I retrieve data from database and display it in datagrid. But, how to display data in Listview. Thanx b4 Best Regards Edwin46 :)

      R Offline
      R Offline
      RepliCrux
      wrote on last edited by
      #2

      Hi, In ListView you will have to Enumerate the datasource and fill it. For example, if your datasource is a DataTable, you can write the following: foreach(DataRow row in table.Rows) { ListViewItem item = new ListViewItem(); item.Text = row["Description"].ToString(); item.Tag = row["ID"].ToString(); //For other coulmns items.SubItems.Add(row["OtherColumn"].ToString(); } Hope this helps.

      1 Reply Last reply
      0
      • E Edwin Syarief

        Hi, i got a problem with my application. Usually I retrieve data from database and display it in datagrid. But, how to display data in Listview. Thanx b4 Best Regards Edwin46 :)

        N Offline
        N Offline
        Nouman Bhatti
        wrote on last edited by
        #3

        u have to get the records through datareader and then iterate through the datareader and add them in the listview one by one if u use listbox in place of listview then u can use the datasource,displaymember,valuemember properties by doing this u can easily bind the data

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups