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:
00669341
Vues:
19
Wow, lotsa information here, Cathi ... thanks!! Did you copy/paste this from documentation? If so, which doc? Obviously something I neglected to read ... <g>

~~Bonnie



>A DataView is, by default, a read-only view of data. However, you can use the DataView to add, delete, or modify rows of data in the underlying table by setting one of three Boolean properties of the DataView. These properties are AllowNew, AllowEdit, and AllowDelete. They are set to true by default, and enable you to specify whether you can modify the data in the underlying DataTable of the DataView.
>
>If AllowNew is true, you can use the AddNew method of the DataView to create a new DataRowView. Note that a new row is not actually added to the underlying DataTable until the EndEdit method of the DataRowView is called. If the CancelEdit method of the DataRowView is called, the new row is discarded. Note also that you can edit only one DataRowView at a time. If you call the AddNew or BeginEdit method of the DataRowView while a pending row exists, EndEdit is implicitly called on the pending row. When EndEdit is called, the changes are applied to the underlying DataTable and can later be committed or rejected using the AcceptChanges or RejectChanges methods of the DataTable, DataSet, or DataRow object. If AllowNew is false, an exception is thrown if you call the AddNew method of the DataRowView.
>
>If AllowEdit is true, you can modify the contents of a DataRow via the DataRowView. You can confirm changes to the underlying row using DataRowView.EndEdit or reject the changes using DataRowView.CancelEdit. Note that only one row can be edited at a time. If you call the AddNew or BeginEdit methods of the DataRowView while a pending row exists, EndEdit is implicitly called on the pending row. When EndEdit is called, proposed changes are placed in the Current row version of the underlying DataRow and can later be committed or rejected using the AcceptChanges or RejectChanges methods of the DataTable, DataSet, or DataRow object. If AllowEdit is false, an exception is thrown if you attempt to modify a value in the DataView.
>
>When an existing DataRowView is being edited, events of the underlying DataTable will still be raised with the proposed changes. Note that if you call EndEdit or CancelEdit on the underlying DataRow, pending changes will be applied or canceled regardless of whether EndEdit or CancelEdit is called on the DataRowView.
>
>If AllowDelete is true, you can delete rows from the DataView using the Delete method of the DataView or DataRowView object and the rows will be deleted from the underlying DataTable. You can later commit or reject the deletes using AcceptChanges or RejectChanges respectively. If AllowDelete is false, an exception is thrown if you call the Delete method of the DataView or DataRowView.
>
>
>>So, a DataView is *always* a subset of a DataSet? IOW, if you are accessing a DataView in a grid and you make changes in that grid, thus making changes in that DataView ... those changes are actually being made in the DataSet?
>>
>>
>>
>>>DataViews allow you to filter and sort data in a DataSet. They allow you to display a sub-set of the records in a DataSet or DataTable as well as filtering the DataSet records using their row state. For example, all rows thast have been changed, or all rows that have been marked for deletion.
>>>
>>>>Thanks Cathi ... as I said, I haven't used DataViews, so I know nothing about them.
>>>>
>>>>What are the pros and cons to using a DataView vs using the DataSet's tables?
>>>>
>>>>~~Bonnie
>>>>
>>>>
>>>>>All DataTables in DataSets have default DataViews that you can use or you can create your own. Even it you use Typed DataSets they are still based on the DataSet so all the capabilites are available.
>>>>>
>>>>>>Hi Cathi,
>>>>>>
>>>>>>Just wondering how this would be handled if you weren't using DataViews, just DataSets (we use typed DataSets). I haven't gotten to the point of messing around with this yet, but will have to soon.
>>>>>>
>>>>>>~~Bonnie
>>>>>>
>>>>>>
>>>>>>>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!
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform