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 Studio 2015 & .NET 4.6
  4. Implement a quick sort algorithm in Data Grid View with button1

Implement a quick sort algorithm in Data Grid View with button1

Scheduled Pinned Locked Moved Visual Studio 2015 & .NET 4.6
helpcssalgorithms
8 Posts 3 Posters 163 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.
  • U Offline
    U Offline
    User 13544494
    wrote on last edited by
    #1

    I'm having trouble with a quick sort algorithm, which is where the grid view data is required to sort by quick sort, and I have 1 table that contains: id_mk, name, address I want to sort id_mk in grid view data results using quick sort with the help of button1 and this id_mk contains the data type string. I thank you for reading this problem, and I hope there is someone who can help me. :) :) :) regards andref

    L J 2 Replies Last reply
    0
    • U User 13544494

      I'm having trouble with a quick sort algorithm, which is where the grid view data is required to sort by quick sort, and I have 1 table that contains: id_mk, name, address I want to sort id_mk in grid view data results using quick sort with the help of button1 and this id_mk contains the data type string. I thank you for reading this problem, and I hope there is someone who can help me. :) :) :) regards andref

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      DataGridView.Sort Method (System.Windows.Forms)[^]

      U 1 Reply Last reply
      0
      • L Lost User

        DataGridView.Sort Method (System.Windows.Forms)[^]

        U Offline
        U Offline
        User 13544494
        wrote on last edited by
        #3

        thank you Richard for the response, how if using code like this in the data grid view Public Sub Quicksort(ByVal list() As Integer, ByVal min As Integer, ByVal max As Integer) Dim random_number As New Random Dim med_value As Integer Dim hi As Integer Dim lo As Integer Dim i As Integer ' If min >= max, the list contains 0 or 1 items so ' it is sorted. If min >= max Then Exit Sub ' Pick the dividing value. i = random_number.Next(min, max + 1) med_value = list(i) ' Swap it to the front. list(i) = list(min) lo = min hi = max Do ' Look down from hi for a value < med_value. Do While list(hi) >= med_value hi = hi - 1 If hi <= lo Then Exit Do Loop If hi <= lo Then list(lo) = med_value Exit Do End If ' Swap the lo and hi values. list(lo) = list(hi) ' Look up from lo for a value >= med_value. lo = lo + 1 Do While list(lo) < med_value lo = lo + 1 If lo >= hi Then Exit Do Loop If lo >= hi Then lo = hi list(hi) = med_value Exit Do End If ' Swap the lo and hi values. list(hi) = list(lo) Loop ' Sort the two sublists. Quicksort(list, min, lo - 1) Quicksort(list, lo + 1, max) End Sub

        L 1 Reply Last reply
        0
        • U User 13544494

          thank you Richard for the response, how if using code like this in the data grid view Public Sub Quicksort(ByVal list() As Integer, ByVal min As Integer, ByVal max As Integer) Dim random_number As New Random Dim med_value As Integer Dim hi As Integer Dim lo As Integer Dim i As Integer ' If min >= max, the list contains 0 or 1 items so ' it is sorted. If min >= max Then Exit Sub ' Pick the dividing value. i = random_number.Next(min, max + 1) med_value = list(i) ' Swap it to the front. list(i) = list(min) lo = min hi = max Do ' Look down from hi for a value < med_value. Do While list(hi) >= med_value hi = hi - 1 If hi <= lo Then Exit Do Loop If hi <= lo Then list(lo) = med_value Exit Do End If ' Swap the lo and hi values. list(lo) = list(hi) ' Look up from lo for a value >= med_value. lo = lo + 1 Do While list(lo) < med_value lo = lo + 1 If lo >= hi Then Exit Do Loop If lo >= hi Then lo = hi list(hi) = med_value Exit Do End If ' Swap the lo and hi values. list(hi) = list(lo) Loop ' Sort the two sublists. Quicksort(list, min, lo - 1) Quicksort(list, lo + 1, max) End Sub

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I am not sure what that is supposed to mean, or what your actual problem is.

          J 1 Reply Last reply
          0
          • L Lost User

            I am not sure what that is supposed to mean, or what your actual problem is.

            J Offline
            J Offline
            Jaroslav Mitrovic
            wrote on last edited by
            #5

            Hi. DataGridView.Sort Method (IComparer) (System.Windows.Forms)[^] I think You dont need a Sort-algorithm inside of a the DataGridView. It is already (halfway) build in the DataGridView. That is the cool Feature of it... To do that use the Button events to apply the Sorting to the Control. Pass in the Parameter to the IComparer, which you need to Implement. And magic... c.u. Zui from Hamburg

            L 1 Reply Last reply
            0
            • J Jaroslav Mitrovic

              Hi. DataGridView.Sort Method (IComparer) (System.Windows.Forms)[^] I think You dont need a Sort-algorithm inside of a the DataGridView. It is already (halfway) build in the DataGridView. That is the cool Feature of it... To do that use the Button events to apply the Sorting to the Control. Pass in the Parameter to the IComparer, which you need to Implement. And magic... c.u. Zui from Hamburg

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              I don't think you meant to post this to me.

              J 1 Reply Last reply
              0
              • U User 13544494

                I'm having trouble with a quick sort algorithm, which is where the grid view data is required to sort by quick sort, and I have 1 table that contains: id_mk, name, address I want to sort id_mk in grid view data results using quick sort with the help of button1 and this id_mk contains the data type string. I thank you for reading this problem, and I hope there is someone who can help me. :) :) :) regards andref

                J Offline
                J Offline
                Jaroslav Mitrovic
                wrote on last edited by
                #7

                Hi. DataGridView.Sort Method (IComparer) (System.Windows.Forms)[^] I think You dont need a Sort-algorithm inside of a the DataGridView. It is already (halfway) build in the DataGridView. That is the cool Feature of it... To do that use the Button events to apply the Sorting to the Control. Pass in the Parameter to the IComparer, which you need to Implement. And magic... c.u. Zui from Hamburg P.S. Replied to the wrong Message.

                1 Reply Last reply
                0
                • L Lost User

                  I don't think you meant to post this to me.

                  J Offline
                  J Offline
                  Jaroslav Mitrovic
                  wrote on last edited by
                  #8

                  Hi. Uuups wrong... Error can´t compute... I was asleep some how, accidantly?! :zzz: You are right, wasn´t a reply to your Message. sry Zui

                  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