Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 that's a standard problem:

Having a list (DataGrid) of the "short version" of some data. Let's 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.

 

I'm 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 I'm not even sure, if my way of trying to solve the problem is a good way (with .NET). Better suggestions are welcome!

 

Thanks,

rman

  • *Experts*
Posted

I assume you're doing databinding to one row in your table? You'll have to use the DataView's Find method to get an index to the row you want (you can also use the DataTable's DefaultView property, which is a DataView). Then set the BindingContext's Position property to that index.

 

There is no built-in "current row" pointer in a DataSet. It's 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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

navigation in DataSets

 

Since I've 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..."

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...