Navigate to certain row in DataSet

rman

New member
Joined
Aug 5, 2003
Messages
2
How can I navigate to a certain row in a DataSet?
I have a DataSet with customer data, I want to reposition to the row where customerID = 4711 (the customerID column is the primary key of the customer table).

Why do I want to do that? I think thats a standard problem:
Having a list (DataGrid) of the "short version" of some data. Lets say: customer data. So you can see only the customer name. In this list you can only select a certain customer, but you can not modify the data. The DataSource for the list is DataSet1 (based on a database view).
For modifying the data there are textboxes with DataSet2 (based on a database table) as their DataSource.
So I want to reposition DataSet2 to that row where the customerID is the customerID of the current row of DataSet1.

Im relatively new into building data applications with .NET, but I have done years of programming with Progress 4GL (and with the 4GL the problem described here is not a problem...). However, so Im not even sure, if my way of trying to solve the problem is a good way (with .NET). Better suggestions are welcome!

Thanks,
rman
 
I assume youre doing databinding to one row in your table? Youll have to use the DataViews Find method to get an index to the row you want (you can also use the DataTables DefaultView property, which is a DataView). Then set the BindingContexts Position property to that index.

There is no built-in "current row" pointer in a DataSet. Its handled through a CurrencyManager object. The BindingContext property on the form is your key to getting there (you can also create your own CurrencyManager).

-Nerseus
 
navigation in DataSets

Since Ive seen that other programmers have similiar problems with trying to navigate through a DataSet, I want to quote something from the help of Visual Studio.

In a chapter named something like "Introduction to DataSets": "...DataSets do not supply the concept of a current data row pointer..."
 
Hi,


so it appears you have a table(s) reflected by a dataset (database view) which is displayed in a datagrid... you select a record in the datagrid and want to be able to edit that row in the textboxes (database table) on the same form...

that is a good question :) but I wonder why you are using the view... you could bind the grid to the (table) dataset and make the grid readonly and bind the textboxes to the same dataset and as you click through the grid records, the same (editable) info is displayed in the textboxes...

If my understanding of the problem is incorrect you could also query the currencymanager of DataSet1 and filter or select DataSet2 based on that query....

eg

[C#]

DataRowView DV1 = (DataRowView)this.DataGridName.BindingContext[DataGridName.DataSource, "TableName"].Current;

DataRowView DV2 = DataSet2.Tables["TableName"].DefaultView.Select("ID_Column = " + DV1["ID_Column"] + ")";

DV2 now holds a DataRowView (direct editable pointers) to the records for the selected row in your table...

does this help?
CS
 
Back
Top