Jump to content
  • Advertisement
Sign in to follow this  

C# Syncronising DataGrid and DataView

This topic is 4902 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();

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!