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. Sorting DataGrid

Sorting DataGrid

Scheduled Pinned Locked Moved C#
csharpalgorithmsquestion
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.
  • M Offline
    M Offline
    Maqsood Ahmed
    wrote on last edited by
    #1

    Hello, How can I sort a DataGridColumn which has Alphanumeric values such that "Record No: x". Is there any property which I can use for this purpose. Scenario: I have 4 values in column R1, R9, R20,R10 and when I try to sort this column in the DataGrid (by clicking the header) it displays R1, R10, R20, R9. While I want to display R1, R9, R10, R20. Is is possible. Thanks in advance Maqsood Ahmed Kolachi Advanced Technologies http://www.kolachi.net

    T 1 Reply Last reply
    0
    • M Maqsood Ahmed

      Hello, How can I sort a DataGridColumn which has Alphanumeric values such that "Record No: x". Is there any property which I can use for this purpose. Scenario: I have 4 values in column R1, R9, R20,R10 and when I try to sort this column in the DataGrid (by clicking the header) it displays R1, R10, R20, R9. While I want to display R1, R9, R10, R20. Is is possible. Thanks in advance Maqsood Ahmed Kolachi Advanced Technologies http://www.kolachi.net

      T Offline
      T Offline
      turbochimp
      wrote on last edited by
      #2

      Would it be possible to pad the numeric portions with zeros? That should yield a more "accurate" sort.

      The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

      M 1 Reply Last reply
      0
      • T turbochimp

        Would it be possible to pad the numeric portions with zeros? That should yield a more "accurate" sort.

        The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

        M Offline
        M Offline
        Maqsood Ahmed
        wrote on last edited by
        #3

        turbochimp wrote: Would it be possible to pad the numeric portions with zeros? Hello, No! the given scenario was just to make the problem clearer. I have sort more complex values in the realtime application, something like "Buy Price 1.2034", "Sell Price 2.382", "Market Price" etc. It means that some values can be alphanumeric but others will be just strings. Can anyone suggest a generic solution to this problem. Bye :) Maqsood Ahmed [MCP,C#] Kolachi Advanced Technologies http://www.kolachi.net

        T 1 Reply Last reply
        0
        • M Maqsood Ahmed

          turbochimp wrote: Would it be possible to pad the numeric portions with zeros? Hello, No! the given scenario was just to make the problem clearer. I have sort more complex values in the realtime application, something like "Buy Price 1.2034", "Sell Price 2.382", "Market Price" etc. It means that some values can be alphanumeric but others will be just strings. Can anyone suggest a generic solution to this problem. Bye :) Maqsood Ahmed [MCP,C#] Kolachi Advanced Technologies http://www.kolachi.net

          T Offline
          T Offline
          turbochimp
          wrote on last edited by
          #4

          It sounds like you need normalization, not a different sort routine. In the example you offer, there should be 3 columns - BuyPrice (decimal), SellPrice (decimal) and MarketPrice (decimal). If you're using a single column to hold three different pieces of data, you should think about changing the way the data is stored and/or displayed.

          The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

          M 1 Reply Last reply
          0
          • T turbochimp

            It sounds like you need normalization, not a different sort routine. In the example you offer, there should be 3 columns - BuyPrice (decimal), SellPrice (decimal) and MarketPrice (decimal). If you're using a single column to hold three different pieces of data, you should think about changing the way the data is stored and/or displayed.

            The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

            M Offline
            M Offline
            Maqsood Ahmed
            wrote on last edited by
            #5

            Hello, It is not the case of storing data in right way or something, it is just for the user friendliness, the way user wants to see it. By the way, there should be only two columns, Price and Type :). Any luck with the actual problem :s Cheers. Maqsood Ahmed [MCP,C#] Kolachi Advanced Technologies http://www.kolachi.net

            T 1 Reply Last reply
            0
            • M Maqsood Ahmed

              Hello, It is not the case of storing data in right way or something, it is just for the user friendliness, the way user wants to see it. By the way, there should be only two columns, Price and Type :). Any luck with the actual problem :s Cheers. Maqsood Ahmed [MCP,C#] Kolachi Advanced Technologies http://www.kolachi.net

              T Offline
              T Offline
              turbochimp
              wrote on last edited by
              #6

              You can always display normalized data in a non-normalized way using SQL functions, string concatenation or by simple control placement. How you display data to the user should not dictate your data model. They seldom coincide. In the example you provided, you would need three columns to hold price information unless you decided to either duplicate all row data for each price type, or move prices to a separate table. One price column in the same table would not cut it. As far as "the actual problem", there isn't one. You're trying to use standard sort routines to sort data in a non-standard way; what's more, your data appears to be stored in a fashion that is not conducive to ever having meaningful reporting or display filtering options. If you are completely devoted to storing your data in the manner you suggest, then I would advise investing some time learning how to implement the IComparable interface, and create your own collection class that's sortable. Please note that this option is less than optimal, to put it mildly.

              The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

              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