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. Link ArrayList to datagridview and display spesific data

Link ArrayList to datagridview and display spesific data

Scheduled Pinned Locked Moved C#
helpcss
4 Posts 4 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.
  • R Offline
    R Offline
    Ronenb
    wrote on last edited by
    #1

    Hi I would like to link ArrayList as datasource to datagridview I’ve defined the ArrayList arrList; arrList = new ArrayList(); //Add data to list arrList.Add(node_1); ... arrList.Add(node_n); dataGridView1.DataSource = arrList; Adding the link is OK, the problem is that I see all the members of nodes in datagridview and I wish to see only specific members in the grid. I try to manually add columns to grid and it didn’t help, I see all members of node in datagridview Please advice Thanks Ronen

    M R H 3 Replies Last reply
    0
    • R Ronenb

      Hi I would like to link ArrayList as datasource to datagridview I’ve defined the ArrayList arrList; arrList = new ArrayList(); //Add data to list arrList.Add(node_1); ... arrList.Add(node_n); dataGridView1.DataSource = arrList; Adding the link is OK, the problem is that I see all the members of nodes in datagridview and I wish to see only specific members in the grid. I try to manually add columns to grid and it didn’t help, I see all members of node in datagridview Please advice Thanks Ronen

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      maybe you should forget the datasource option and update the grid view as required by looping through the array list. That way you can display what ever you want how you want, much more control that way :)

      1 Reply Last reply
      0
      • R Ronenb

        Hi I would like to link ArrayList as datasource to datagridview I’ve defined the ArrayList arrList; arrList = new ArrayList(); //Add data to list arrList.Add(node_1); ... arrList.Add(node_n); dataGridView1.DataSource = arrList; Adding the link is OK, the problem is that I see all the members of nodes in datagridview and I wish to see only specific members in the grid. I try to manually add columns to grid and it didn’t help, I see all members of node in datagridview Please advice Thanks Ronen

        R Offline
        R Offline
        Reza Raad
        wrote on last edited by
        #3

        See this is my code same as you want , this works for me correctly: grdRequests.Columns.Clear(); loanRequests = //get your array list here grdRequests.DataSource = loanRequests; grdRequests.DataKeyNames = new string[] { "ID" }; CommandField SelectField = new CommandField(); SelectField.SelectText = "field1"; SelectField.ShowSelectButton = true; grdRequests.Columns.Add(SelectField); BoundField IDField = new BoundField(); IDField.DataField = "ID"; IDField.HeaderText = "field2"; grdRequests.Columns.Add(IDField); ... grdRequests.DataBind();

        Human knowledge belongs to the world

        1 Reply Last reply
        0
        • R Ronenb

          Hi I would like to link ArrayList as datasource to datagridview I’ve defined the ArrayList arrList; arrList = new ArrayList(); //Add data to list arrList.Add(node_1); ... arrList.Add(node_n); dataGridView1.DataSource = arrList; Adding the link is OK, the problem is that I see all the members of nodes in datagridview and I wish to see only specific members in the grid. I try to manually add columns to grid and it didn’t help, I see all members of node in datagridview Please advice Thanks Ronen

          H Offline
          H Offline
          Henry Minute
          wrote on last edited by
          #4

          The DataGridView will automatically show ALL public properties of your Node class. So you could do as musefan has suggested, or a possible alternative is to create a new class 'GriddableNode' which holds only the properties you wish to display, then create a list of some sort to use as the datasource for the DataGridView. OR you could edit the columns of the DataGridView, use the SmartTag for the gridview in the designer.

          Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.

          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