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. Determine Collection Type at run time

Determine Collection Type at run time

Scheduled Pinned Locked Moved C#
tutorial
4 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.
  • X Offline
    X Offline
    xdavidx
    wrote on last edited by
    #1

    I am trying to make a generic form that has a datagridview on it. I want to be able to send in multiple types of collections, the type will be determined at runtime, to the form to be bound to the datagridview. Im guessing I need to use generics for this, but Im not sure how to do it. thanks :)

    C 1 Reply Last reply
    0
    • X xdavidx

      I am trying to make a generic form that has a datagridview on it. I want to be able to send in multiple types of collections, the type will be determined at runtime, to the form to be bound to the datagridview. Im guessing I need to use generics for this, but Im not sure how to do it. thanks :)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      No, you probably want to use IEnumerable, or some other interface that is common to collection classes.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      X 1 Reply Last reply
      0
      • C Christian Graus

        No, you probably want to use IEnumerable, or some other interface that is common to collection classes.

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        X Offline
        X Offline
        xdavidx
        wrote on last edited by
        #3

        I tried using IEnumerable but I could not convert List<> to use it. Am I doing something wrong?

        V 1 Reply Last reply
        0
        • X xdavidx

          I tried using IEnumerable but I could not convert List<> to use it. Am I doing something wrong?

          V Offline
          V Offline
          Vikram A Punathambekar
          wrote on last edited by
          #4

          IEnumeration is an interface that your collection has to implement. There are plenty of samples on implementing IEnumerable. :) Once you've done that, you can simply use foreach to iterate over the collection.

          Cheers, Vıkram.


          After all is said and done, much is said and little is done.

          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