Datagrid Control Issue

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The program was written by a different developer who never finished it.
Basically, it is a front-end to an Access database that probably should have
been done in Access itself. My question concerns the DataGrid control. This
control is used on about 30 different forms. The user wants to be able to
sort the data in a grid by clicking a column header. The AllowSorting
property is turned off on every grid in the project. I thought the fix would
be to set AllowSorting to true, but it is not that simple. If I set
AllowSorting to true, select a row, and click the Edit button, a form pops up
and displays the data that matched that row before the sort was performed.
For example, of the grid contains one column and three rows of data, B, C, A,
if I click the column header, the data is sorted as A, B, C. This appears
correct. However, if I select the second row, Instead of C, it displays B,
the data that was originally in that row.

Do you have any idea how to handle this? I have searched Google and Yahoo
for about 3 hours and I am getting some close, but no solid information. The
DataGrid is bound to a DataSet. I believe that sorting the grid does not
change the sort order of the underlying data. It just changes the way the
data is presented. This does make sense to me. If there was an event that
was fired when a sort is performed, maybe there is a way to resort that data
at that point. One other quirky thing that happens is every time I Edit
data, when I close the Edit form, the sort order reverts to what it
originally was. I don’t want that to happen.
 
Hi, John R. Dougherty
Solution:
Bind DataView to DataGrid.DataSource instead of binding DataTable to
DataGrid.DataSource.
The Data you use it for displaying should be from
DataView.item(datagrid.CurrentRowIndex).row, not from DataTable.row(
datagrid.CurrentRowIndex).
The issue is because datagrid is mapped to dataview, not mapped to DataTable.

Good luck
 
Back
Top