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. datagrid sorting hassles

datagrid sorting hassles

Scheduled Pinned Locked Moved C#
tutorialdatabasealgorithmsquestion
2 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.
  • S Offline
    S Offline
    steven shingler
    wrote on last edited by
    #1

    Hi all, I've got a datagrid. I have a function which selects certain rows in a datagrid thus: public void selectRows(string key, string columnName) { int count = 0; foreach(DataRow dr in ((DataView)dg_aspects.DataSource).Table.Rows) { if(dr[columnName].ToString()==key) dg_aspects.Select(count); else dg_aspects.UnSelect(count); count++; } } This works, but when the user clicks a column header to sort the datagrid, the selected columns remain at the same index. For example - if the top two rows are selected initially. After sort - the top two rows are still selected, but the datagrid is showing different results in those rows. It appears that the DataTable the DataGrid is showing, and the DataDource we work with aren't the same where sorting is concerned. Does anyone know how to get a handle on the sorted DataTable? I hope that's clear - thanks for taking a look Steven

    L 1 Reply Last reply
    0
    • S steven shingler

      Hi all, I've got a datagrid. I have a function which selects certain rows in a datagrid thus: public void selectRows(string key, string columnName) { int count = 0; foreach(DataRow dr in ((DataView)dg_aspects.DataSource).Table.Rows) { if(dr[columnName].ToString()==key) dg_aspects.Select(count); else dg_aspects.UnSelect(count); count++; } } This works, but when the user clicks a column header to sort the datagrid, the selected columns remain at the same index. For example - if the top two rows are selected initially. After sort - the top two rows are still selected, but the datagrid is showing different results in those rows. It appears that the DataTable the DataGrid is showing, and the DataDource we work with aren't the same where sorting is concerned. Does anyone know how to get a handle on the sorted DataTable? I hope that's clear - thanks for taking a look Steven

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Use a DataView to sort the data in the table. xacc-ide 0.0.12 now with C#, MSIL, C, XML, ASP.NET and HLSL coloring - Screenshots

      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