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. Getting the column items in a datagrid

Getting the column items in a datagrid

Scheduled Pinned Locked Moved C#
database
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.
  • W Offline
    W Offline
    Wamuti
    wrote on last edited by
    #1

    I have a datagrid that is having values from a database. I need the values in the second column (being zero index based, i know if there is any indexing i will index as 1) but i am totally unable to get these items. i don't want to query the database again because this will slow down my system so much. please assist on how i can get this items. I tried this but did not work:

    ArrayList percentages = new ArrayList();
    percentages.AddRange(dataGridInfo.Columns[1]);

    Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.

    D M D 3 Replies Last reply
    0
    • W Wamuti

      I have a datagrid that is having values from a database. I need the values in the second column (being zero index based, i know if there is any indexing i will index as 1) but i am totally unable to get these items. i don't want to query the database again because this will slow down my system so much. please assist on how i can get this items. I tried this but did not work:

      ArrayList percentages = new ArrayList();
      percentages.AddRange(dataGridInfo.Columns[1]);

      Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      If you need [Edit] to process [/Edit] them(the datas) in memory I would go for a List<YourClass> myList and then set the datagrid.DataSource = myList; Somethin like:

      //gets the data
      public ... GetDatas(){
      cmd.CommandText = "SELECT * FROM XYZ";//or "EXEC SomeProcedure" or....;
      SQLDataReader dr = cmd.ExecuteReader();
      MyClass curr = null;
      List<MyClass> lst = new List<MyClass>;
      while(dr.Read()){
      curr = new MyClass();
      curr.Myprop1 = dr.GetString(0);//or GetWhatever
      ...
      lst.Add(curr);
      }
      ...
      return lst;
      }

      //and outside, somewhere in your UI
      var myList = GetDatas();
      dataGridView1.DataSource = myList

      Now you have the List and you can LINQ or whatever;

      modified on Sunday, February 28, 2010 11:35 AM

      1 Reply Last reply
      0
      • W Wamuti

        I have a datagrid that is having values from a database. I need the values in the second column (being zero index based, i know if there is any indexing i will index as 1) but i am totally unable to get these items. i don't want to query the database again because this will slow down my system so much. please assist on how i can get this items. I tried this but did not work:

        ArrayList percentages = new ArrayList();
        percentages.AddRange(dataGridInfo.Columns[1]);

        Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        Is this the asp.net gridview of the winforms datagridview, 2 very different beasites. Winforms you can use datagridview.columns[index] to get the column.

        Never underestimate the power of human stupidity RAH

        1 Reply Last reply
        0
        • W Wamuti

          I have a datagrid that is having values from a database. I need the values in the second column (being zero index based, i know if there is any indexing i will index as 1) but i am totally unable to get these items. i don't want to query the database again because this will slow down my system so much. please assist on how i can get this items. I tried this but did not work:

          ArrayList percentages = new ArrayList();
          percentages.AddRange(dataGridInfo.Columns[1]);

          Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.

          D Offline
          D Offline
          DX Roster
          wrote on last edited by
          #4

          Try this code sure it will help you Label myLabel = (Label)myGridView.Rows[myGridView.SelectedIndex].Cells[2].FindControl("myLabel");

          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