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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. DataSet to List<>

DataSet to List<>

Scheduled Pinned Locked Moved C#
question
6 Posts 2 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.
  • I Offline
    I Offline
    Illegal Operation
    wrote on last edited by
    #1

    Hi! How can I take data from a dataset and populate a List<>()?

    Illegal Operation

    L 1 Reply Last reply
    0
    • I Illegal Operation

      Hi! How can I take data from a dataset and populate a List<>()?

      Illegal Operation

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      A List of what type? You could use Add to add an instance of type T to a List<T> You could use Add to add a DataSet to a List<DateSet> So what is it you want? :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      Prolific encyclopedia fixture proof-reader browser patron addict?
      We all depend on the beast below.


      I 1 Reply Last reply
      0
      • L Luc Pattyn

        A List of what type? You could use Add to add an instance of type T to a List<T> You could use Add to add a DataSet to a List<DateSet> So what is it you want? :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        Prolific encyclopedia fixture proof-reader browser patron addict?
        We all depend on the beast below.


        I Offline
        I Offline
        Illegal Operation
        wrote on last edited by
        #3

        I need to create a list of type Dataset. Here is my code at the moment

        List<> dsList = new List<>();

        dsList.Add(payClass.GetPayItems());

        How would I bind that list to a ListBox? P.S - I added to << and >> because when posting it removes it.

        Illegal Operation

        L 1 Reply Last reply
        0
        • I Illegal Operation

          I need to create a list of type Dataset. Here is my code at the moment

          List<> dsList = new List<>();

          dsList.Add(payClass.GetPayItems());

          How would I bind that list to a ListBox? P.S - I added to << and >> because when posting it removes it.

          Illegal Operation

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          A ListBox can hold and show all kinds of items; by default, it calls ToString() on each of its items to visualize them. There is an alternative by turning the ListBox into "OwnerDrawn" mode, which means you set out to provide all the code required to paint one item, see the DrawItem event. If you were to bind a List<DataSet> to a ListBox, it would turn each DataSet into a single item in its collection; unless your DataSet has overridden its ToString() method, the net result would be something similar to the string "System.Data.DataSet" which I guess is not what you want. And painting a DataSet yourself would be a challenge. So I think you are tackling this the wrong way. I'm not so sure what it is you really want to achieve. PS: you can get proper < > & signs by using the little widgets above the editor box. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          Prolific encyclopedia fixture proof-reader browser patron addict?
          We all depend on the beast below.


          I 1 Reply Last reply
          0
          • L Luc Pattyn

            A ListBox can hold and show all kinds of items; by default, it calls ToString() on each of its items to visualize them. There is an alternative by turning the ListBox into "OwnerDrawn" mode, which means you set out to provide all the code required to paint one item, see the DrawItem event. If you were to bind a List<DataSet> to a ListBox, it would turn each DataSet into a single item in its collection; unless your DataSet has overridden its ToString() method, the net result would be something similar to the string "System.Data.DataSet" which I guess is not what you want. And painting a DataSet yourself would be a challenge. So I think you are tackling this the wrong way. I'm not so sure what it is you really want to achieve. PS: you can get proper < > & signs by using the little widgets above the editor box. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            Prolific encyclopedia fixture proof-reader browser patron addict?
            We all depend on the beast below.


            I Offline
            I Offline
            Illegal Operation
            wrote on last edited by
            #5

            Luc, I have dataset that contains Items from my database. What I want to do is list all those payitems in listbox1 and then enable to user to add selecteditems to listbox2.

            Illegal Operation

            L 1 Reply Last reply
            0
            • I Illegal Operation

              Luc, I have dataset that contains Items from my database. What I want to do is list all those payitems in listbox1 and then enable to user to add selecteditems to listbox2.

              Illegal Operation

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Well, AFAIK a DataSet can only contain DataTables; so maybe you have one or several DataTables that hold DataRows with such payitem information. The easy way of presenting one DataTable to a user is by using a DataGridView (assuming you are talking about a WinForms application). While I'm not an expert on DataTables and the like, I recently published my CP Vanity[^] article that uses both DataTable and DataGridView. I would suggest you read the MSDN documentation on the relevant classes, and have a look at my app. Assuming it looks like what you have in mind. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              Prolific encyclopedia fixture proof-reader browser patron addict?
              We all depend on the beast below.


              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