Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Determining the row position in a dataset
Message
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Divers
Thread ID:
00667651
Message ID:
00667679
Vues:
23
In Visual Studio .NET, data sources do not maintain a notion of a control's
position within the data contained. In contrast, other data-access
technologies, such as ADO, typically maintain a current record and provide
ways for you to navigate to other records. Some people may be surprised to
see that the data no longer "knows" where the current record is itself, due
to the absence of a cursor. Now, without cursors, you can have multiple
positions set on the same store of data.

You should use the Find method of the DataView. This
method returns the item number for that row. Then, just assign it to the
position property of the CurrencyManager. You can get the DataView by
casting the List property of the CurrencyManager. The Find method searches
the sorted column(s), so you would have to sort by the key field.

In this sample, you use the DataView.Find method to retrieve the record
position
and update the CurrencyManager object. This synchronizes the row pointer in
the
DataGrid. If you want to highlight the row beyond this, you can use the
DataGrid.Select method.

The
following Knowledge Base article demonstrates a searchable DataGrid:

Q308070 HOW TO: Implement a Searchable DataGrid by Using ADO.NET

Here is a portion of the article that pertains to what you doing:

This sample uses the CurrencyManager object to manipulate currency. You can
also
use the BindingManagerBase class, which is the base class for the
CurrencyManager. All data binding is done through DataView classes. To
synchronize your controls and the CurrencyManager, the controls must be
bound to
the same DataView.

'Search for the record in the DefaultView.
'If found, move the pointer to the correct record in the grid.
Dim i As Integer
i = dv.Find(txtFind.Text) ' Locates record in DefaultView.
' Does not move grid pointer or CM.
If i > dv.Table.Rows.Count Or i < 0 Then
MsgBox("Record Not found", MsgBoxStyle.Information, "Record Not
Found")
Else
'CM.Position = i ' Synchronizes Cm and Grid Pointer.
End If



>I am looking for a way to set the CurrencyManager.Position when I know the datarow.
>
>My specific problem: I have an array of child datarows, each with a specific rowid within the form's dataset. I want to set currencymanager.position to a selected child record - this updates my displayed values based on the databindings I've established for the form controls.
>
>The datarow object contains a member named rowid. Rowid holds an integer which corresponds to the value I want to set to currencymanager.position, however, the rowid member is private and can not be accessed programatically.
>
>Does anyone know any workaround for this problem? Any direction would be greatly appreciated!
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform