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. access rows in order that they appear after sorting datagrid

access rows in order that they appear after sorting datagrid

Scheduled Pinned Locked Moved C#
questioncssalgorithms
3 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.
  • B Offline
    B Offline
    blakeb_1
    wrote on last edited by
    #1

    Hello, I am trying to print out a datagrid, and I have code that works fine, but it won't print the data in sorted order if it has been sorted in the datagrid. It still prints the original order. How can I access the rows in sorted order instead of in the original order? theTable.Rows[i] is what I've been using to loop through the rows, but is there anything else I can use so that I can print the grid sorted. Thanks, Blake

    H 1 Reply Last reply
    0
    • B blakeb_1

      Hello, I am trying to print out a datagrid, and I have code that works fine, but it won't print the data in sorted order if it has been sorted in the datagrid. It still prints the original order. How can I access the rows in sorted order instead of in the original order? theTable.Rows[i] is what I've been using to loop through the rows, but is there anything else I can use so that I can print the grid sorted. Thanks, Blake

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      DataTable.Rows will always present the original order, but you can use a DataView to sort and get the sorted order of the contained DataRows. You can do this like so:

      DataView view = new DataView(myDataTable);
      view.Sort = "myIDColumn";
      foreach (DataRowView rowView in view)
      Console.WriteLine(rowView.Row.ItemArray);

      You should be able to get this using theTable.DefaultView, which should return the DataView in its current state that the DataGrid used to sort or filter the data.

      Microsoft MVP, Visual C# My Articles

      B 1 Reply Last reply
      0
      • H Heath Stewart

        DataTable.Rows will always present the original order, but you can use a DataView to sort and get the sorted order of the contained DataRows. You can do this like so:

        DataView view = new DataView(myDataTable);
        view.Sort = "myIDColumn";
        foreach (DataRowView rowView in view)
        Console.WriteLine(rowView.Row.ItemArray);

        You should be able to get this using theTable.DefaultView, which should return the DataView in its current state that the DataGrid used to sort or filter the data.

        Microsoft MVP, Visual C# My Articles

        B Offline
        B Offline
        blakeb_1
        wrote on last edited by
        #3

        Thanks!!

        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