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. Adding Ranking Column (just a column incrementing by 1 each row) to datagrid

Adding Ranking Column (just a column incrementing by 1 each row) to datagrid

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
6 Posts 2 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.
  • C Offline
    C Offline
    cavall
    wrote on last edited by
    #1

    Can someone tell me how to make a column in a datagrid that simply puts the number of the record in its field? ie: (Rnk Column) Rnk Name 1 aaa 2 bbb 3 ccc 4 ddd Thanks Cavall "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

    P 1 Reply Last reply
    0
    • C cavall

      Can someone tell me how to make a column in a datagrid that simply puts the number of the record in its field? ie: (Rnk Column) Rnk Name 1 aaa 2 bbb 3 ccc 4 ddd Thanks Cavall "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

      P Offline
      P Offline
      partt
      wrote on last edited by
      #2

      Public Shared Function Rank() As DataTable Dim ds As DataSet = SqlHelper.ExecuteDatase(ConfigurationSettings.AppSettings(myProj.ConnectionString), "usp_GetRankedList") Dim dt As New DataTable() dt.Columns.Add("Rank") dt.Columns.Add("Name") Dim r As DataRow Dim workRow As DataRow Dim i As Integer = 1 For Each r In ds.Tables(0).Rows workRow = dt.NewRow workRow("Rank") = i workRow("Name") = r("Name") dt.Rows.Add(workRow) i += 1 Next Return dt End Function Watch for line break! Have fun!

      C 1 Reply Last reply
      0
      • P partt

        Public Shared Function Rank() As DataTable Dim ds As DataSet = SqlHelper.ExecuteDatase(ConfigurationSettings.AppSettings(myProj.ConnectionString), "usp_GetRankedList") Dim dt As New DataTable() dt.Columns.Add("Rank") dt.Columns.Add("Name") Dim r As DataRow Dim workRow As DataRow Dim i As Integer = 1 For Each r In ds.Tables(0).Rows workRow = dt.NewRow workRow("Rank") = i workRow("Name") = r("Name") dt.Rows.Add(workRow) i += 1 Next Return dt End Function Watch for line break! Have fun!

        C Offline
        C Offline
        cavall
        wrote on last edited by
        #3

        thanks for the reply, but my main problem is this... i have another table in a dataset that I want to joing, say to that table you just created, link them on a field, and then pull the results from that join. ie. all the fields from the second table and the rank field on the first table.. the join would, for example, be on the "Name" field... Got any ideas? Thanks cavall "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

        P 1 Reply Last reply
        0
        • C cavall

          thanks for the reply, but my main problem is this... i have another table in a dataset that I want to joing, say to that table you just created, link them on a field, and then pull the results from that join. ie. all the fields from the second table and the rank field on the first table.. the join would, for example, be on the "Name" field... Got any ideas? Thanks cavall "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

          P Offline
          P Offline
          partt
          wrote on last edited by
          #4

          If you are using a stored procedure, you should probably take care of any joining you want to do there. Just use the vbDataGrid for display. If you go this way I've found www.sqlteam/forums to be very helpful if you are unsure of how to put that stored procedure together. Good luck

          C 1 Reply Last reply
          0
          • P partt

            If you are using a stored procedure, you should probably take care of any joining you want to do there. Just use the vbDataGrid for display. If you go this way I've found www.sqlteam/forums to be very helpful if you are unsure of how to put that stored procedure together. Good luck

            C Offline
            C Offline
            cavall
            wrote on last edited by
            #5

            is there a way around not using stored procedures? It is a lengthy process to get our DBA to create those procedures and so being able to do joins on the fly in vs.net would be awesome... do you know of a way to do this? thanks cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

            P 1 Reply Last reply
            0
            • C cavall

              is there a way around not using stored procedures? It is a lengthy process to get our DBA to create those procedures and so being able to do joins on the fly in vs.net would be awesome... do you know of a way to do this? thanks cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson

              P Offline
              P Offline
              partt
              wrote on last edited by
              #6

              I'm sure there is a way around it, I'm not familiar with it though, it's not considered "best practice". www.msdn.com may help, or maybe you could post a topic based on that.

              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