Programmatically populate grid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Kelley

    Programmatically populate grid

    Is it possible to populate a grid using code (not binding it to a
    datasource). Is there something like an additem method?

    Thanks,



  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Programmaticall y populate grid

    Tim,

    No, there isn't. You need to find a class that implements IList and
    then bind to that.

    DataSet classes are disconnected data, meaning that you don't need a
    database in order to use them. They also have designer support, so you
    should just use that in your program and bind to that (populating that
    programatically ).

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Tim Kelley" <tkelley@compan y.comwrote in message
    news:uTyN4kY6GH A.4500@TK2MSFTN GP02.phx.gbl...
    Is it possible to populate a grid using code (not binding it to a
    datasource). Is there something like an additem method?
    >
    Thanks,
    >
    >
    >

    Comment

    • Tim Kelley

      #3
      Re: Programmaticall y populate grid

      I gave that a try. I created my dataset and datatable and populated it
      with the data I need.
      I bound the dataviewgrid to the dataset, but no records show in my grid. I
      have checked the datatable and there are actually records in the table. Am
      I missing something? Here is the code I am using:

      DataSet dsgrid = new DataSet();

      DataTable workTable = new DataTable();

      dsgrid.Tables.A dd("tablename") ;

      workTable.Colum ns.Add("field1" , typeof(String)) ;

      workTable.Colum ns.Add("field2" , typeof(String)) ;

      workTable.Colum ns.Add("field3" , typeof(String)) ;

      code to populate table

      dataGridView1.D ataSource = dsgrid.Tables[0];


      Thanks,


      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in
      message news:%23yjMhUZ6 GHA.2364@TK2MSF TNGP02.phx.gbl. ..
      Tim,
      >
      No, there isn't. You need to find a class that implements IList and
      then bind to that.
      >
      DataSet classes are disconnected data, meaning that you don't need a
      database in order to use them. They also have designer support, so you
      should just use that in your program and bind to that (populating that
      programatically ).
      >
      Hope this helps.
      >
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m
      >
      "Tim Kelley" <tkelley@compan y.comwrote in message
      news:uTyN4kY6GH A.4500@TK2MSFTN GP02.phx.gbl...
      >Is it possible to populate a grid using code (not binding it to a
      >datasource). Is there something like an additem method?
      >>
      >Thanks,
      >>
      >>
      >>
      >
      >

      Comment

      Working...