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