Sign in to follow this  

C# Syncronising DataGrid and DataView

This topic is 4598 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites

This topic is 4598 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this