C# Syncronising DataGrid and DataView

Started by
-1 comments, last by PhilHalf 18 years, 11 months ago
Hi, I'm trying to learn some C# data access and have come across a problem with my DataGrid. I have a DataGrid control that is bound to a DataView. I'm using a DataView so that I can prevent editing, new records etc. When you right click on a record and select an option from the menu, it will take you to a new screen and populate the form with the data relevant to that record. The problem that I've got is that if the order of the datagrid is changed, the index refers to a different record to that of the DataView itself.

// dgSearchResults is my DataGrid
DataView dwSelection = (DataView)dgSearchResults.DataSource;
object orderID = dwSelection.Table.Rows[dgSearchResults.CurrentCell.RowNumber]["orderID"];

frmOrders frm = new frmOrders();
frm.GetOrder(orderID.ToString());
frm.Show();



Say for example I have 2 records with order ids 1 and 2. If the datagrid is showing in ascending order (default) and I select record 2 for example, it will take me to the correct details in the order frm. However, if I sort the order ids in descending order and click on the first record (order id 2), the index is still 1 and seems to refer to the record at index 1 in the DataView. I understand that it's possible to syncronise the DataGrid and the DataView using a BindingManager, but I can't find any information on how to do it. What I have found isn't explained very well or seems to be used for something different. Will a BindingManager even do what I'm after? Thanks in advance for any help or advice, PhilHalf [Edited by - PhilHalf on May 16, 2005 2:26:54 PM]

This topic is closed to new replies.

Advertisement