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. Problem with deleting a row from a sorted DataGrid

Problem with deleting a row from a sorted DataGrid

Scheduled Pinned Locked Moved C#
cssdatabasealgorithmsbeta-testingregex
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.
  • L Offline
    L Offline
    Larantz
    wrote on last edited by
    #1

    Hi. I was wondering if anyone has a solution to my problem. I'm currently working with an application that consists of a Datagrid containing files and filedata. As long as I don't sort the table, using columnheaders, retrieving the selectedindex and deleting it from the DataTable is of no problem. But when I sort the DataGrid my indexes become like this: Before sorting: => After sorting on i.e. column "Fileset": ------------------------------------------------------------------------------------------ [Grid/Table index 0] File1.txt FilesetB => [Gridindex 0][Tableindex 3] File4.txt FilsetA [Grid/Table index 1] File2.txt FilesetC => [Gridindex 1][Tableindex 0] File1.txt FilsetB [Grid/Table index 2] File3.txt FilesetC => [Gridindex 2][Tableindex 4] File5.txt FilsetB [Grid/Table index 3] File4.txt FilesetA => [Gridindex 3][Tableindex 1] File2.txt FilsetC [Grid/Table index 4] File5.txt FilesetB => [Gridindex 4][Tableindex 2] File3.txt FilsetC If I highlight File3.txt after sorting, I retrieve DataGrid index 4, but index 4 in the DataTable equals File5.txt, and this file is deleted instead. Is there a way of either retrieving data from the grid that I can search for in table for deletion, or sorting the table to match indexes with the grid, or lastly synchronize the grid and the table? I'm kinda new to DataGrids and the only way I know of getting data is through DataSets. I'd really appreciate some feedback :) Best regards! -Larantz- -- modified at 8:34 Tuesday 25th April, 2006

    R 1 Reply Last reply
    0
    • L Larantz

      Hi. I was wondering if anyone has a solution to my problem. I'm currently working with an application that consists of a Datagrid containing files and filedata. As long as I don't sort the table, using columnheaders, retrieving the selectedindex and deleting it from the DataTable is of no problem. But when I sort the DataGrid my indexes become like this: Before sorting: => After sorting on i.e. column "Fileset": ------------------------------------------------------------------------------------------ [Grid/Table index 0] File1.txt FilesetB => [Gridindex 0][Tableindex 3] File4.txt FilsetA [Grid/Table index 1] File2.txt FilesetC => [Gridindex 1][Tableindex 0] File1.txt FilsetB [Grid/Table index 2] File3.txt FilesetC => [Gridindex 2][Tableindex 4] File5.txt FilsetB [Grid/Table index 3] File4.txt FilesetA => [Gridindex 3][Tableindex 1] File2.txt FilsetC [Grid/Table index 4] File5.txt FilesetB => [Gridindex 4][Tableindex 2] File3.txt FilsetC If I highlight File3.txt after sorting, I retrieve DataGrid index 4, but index 4 in the DataTable equals File5.txt, and this file is deleted instead. Is there a way of either retrieving data from the grid that I can search for in table for deletion, or sorting the table to match indexes with the grid, or lastly synchronize the grid and the table? I'm kinda new to DataGrids and the only way I know of getting data is through DataSets. I'd really appreciate some feedback :) Best regards! -Larantz- -- modified at 8:34 Tuesday 25th April, 2006

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      Hi, the DataGrid has an indexer which you could use:

      object value = myGrid[0, 1];

      The other possibility would be to access the data through the DefaultView of the table you have bound to the grid. It is the one actually doing the sorting and thus accessing the data with it will always be in the correct order.

      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