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. Visual Basic
  4. Looping thru one column

Looping thru one column

Scheduled Pinned Locked Moved Visual Basic
help
9 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.
  • Z Offline
    Z Offline
    zchwllms
    wrote on last edited by
    #1

    Hello all I have a datagrid that i need to loop through the column called TABLE_NAME and use all the cells that end with the word "Data". ANY help is appreciated. I have included a small snippet: Dim dt As DataTable = acc_connect.GetSchema("tables") GridView1.DataSource = dt GridView1.SelectAll() For Each r As DataGridViewCell In GridView1.SelectedCells Dim str As String = r.Value.ToString Dim i As Integer = str.IndexOf("Data") If Not i = -1 Then But this in no way works, thanks in advance!!!

    L G 2 Replies Last reply
    0
    • Z zchwllms

      Hello all I have a datagrid that i need to loop through the column called TABLE_NAME and use all the cells that end with the word "Data". ANY help is appreciated. I have included a small snippet: Dim dt As DataTable = acc_connect.GetSchema("tables") GridView1.DataSource = dt GridView1.SelectAll() For Each r As DataGridViewCell In GridView1.SelectedCells Dim str As String = r.Value.ToString Dim i As Integer = str.IndexOf("Data") If Not i = -1 Then But this in no way works, thanks in advance!!!

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

      Hi,

      zchwllms wrote:

      But this in no way works

      that's not informative; you should explain what it does and how that differs from what you want, otherwise we have to guess. There is a String.EdsWith() method that will interest you. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


      Z 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi,

        zchwllms wrote:

        But this in no way works

        that's not informative; you should explain what it does and how that differs from what you want, otherwise we have to guess. There is a String.EdsWith() method that will interest you. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


        Z Offline
        Z Offline
        zchwllms
        wrote on last edited by
        #3

        Yes, sorry about that, well as of right now I am getting the column heading as the value and what I is whatever is in the cell on that column. I was looking for somthing like: for each r as string in datagridview.column if r.endswith("Data") then 'the rest of my code will go here next thanks again

        L 1 Reply Last reply
        0
        • Z zchwllms

          Yes, sorry about that, well as of right now I am getting the column heading as the value and what I is whatever is in the cell on that column. I was looking for somthing like: for each r as string in datagridview.column if r.endswith("Data") then 'the rest of my code will go here next thanks again

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

          Hi, a DataGridViewCell holds an Object, so the Value property returns that object. All objects inherit ToString() method from class Object, it simply returns the type string. So whatever your DGVC is actually holding, you should either override its ToString() to return real content, or provide (and use) another way to retrieve its representation (some classes have a GetTect method for this). :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


          Z 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, a DataGridViewCell holds an Object, so the Value property returns that object. All objects inherit ToString() method from class Object, it simply returns the type string. So whatever your DGVC is actually holding, you should either override its ToString() to return real content, or provide (and use) another way to retrieve its representation (some classes have a GetTect method for this). :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


            Z Offline
            Z Offline
            zchwllms
            wrote on last edited by
            #5

            Thank you for elaborating, I am pretty new to this whole thing. But my question is still how do I loop through these cells(only in one column) to actually get the content of the cell into a variable string. I understand the logic I am just not sure on how to actually pull the content out of the cell for usage. thanks, zach

            L 1 Reply Last reply
            0
            • Z zchwllms

              Thank you for elaborating, I am pretty new to this whole thing. But my question is still how do I loop through these cells(only in one column) to actually get the content of the cell into a variable string. I understand the logic I am just not sure on how to actually pull the content out of the cell for usage. thanks, zach

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

              Hi, I haven't used DataGridView myself, here is my best guess: - DGV has a property called Rows, this holds all the rows, so you can iterate them with a foreach (DataGridViewRow row in myDGV.Rows) {...} - a DataGridViewRow has a property called Cells, this holds all the cells of that row, as in one array; you can apply an index to them as in row.Cells[i]; - with the above, you could access all the cells that belong to a single column, provided you now the index of that column. If you have to find out that index, well DGV has a property called Columns, this holds all the column descriptions (not the data, just metadata). I hope and think that would put you on track. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


              Z 1 Reply Last reply
              0
              • L Luc Pattyn

                Hi, I haven't used DataGridView myself, here is my best guess: - DGV has a property called Rows, this holds all the rows, so you can iterate them with a foreach (DataGridViewRow row in myDGV.Rows) {...} - a DataGridViewRow has a property called Cells, this holds all the cells of that row, as in one array; you can apply an index to them as in row.Cells[i]; - with the above, you could access all the cells that belong to a single column, provided you now the index of that column. If you have to find out that index, well DGV has a property called Columns, this holds all the column descriptions (not the data, just metadata). I hope and think that would put you on track. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


                Z Offline
                Z Offline
                zchwllms
                wrote on last edited by
                #7

                thanks for your help

                1 Reply Last reply
                0
                • Z zchwllms

                  Hello all I have a datagrid that i need to loop through the column called TABLE_NAME and use all the cells that end with the word "Data". ANY help is appreciated. I have included a small snippet: Dim dt As DataTable = acc_connect.GetSchema("tables") GridView1.DataSource = dt GridView1.SelectAll() For Each r As DataGridViewCell In GridView1.SelectedCells Dim str As String = r.Value.ToString Dim i As Integer = str.IndexOf("Data") If Not i = -1 Then But this in no way works, thanks in advance!!!

                  G Offline
                  G Offline
                  GuyThiebaut
                  wrote on last edited by
                  #8

                  How about this: Create a dataview filtering on column TABLE_NAME like %data. Then just loop through this dataview. Guy

                  You always pass failure on the way to success.

                  Z 1 Reply Last reply
                  0
                  • G GuyThiebaut

                    How about this: Create a dataview filtering on column TABLE_NAME like %data. Then just loop through this dataview. Guy

                    You always pass failure on the way to success.

                    Z Offline
                    Z Offline
                    zchwllms
                    wrote on last edited by
                    #9

                    Sounds interesting, could you say more about filtering on a column, I do not have the slightest clue as how to do this. Would it be done with SQL statement or in VB.NET code? thanks, Zach

                    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