DataView - How to access the row in the datatable behind the DataView

R

Richard

Windows Forms, csharp, 20 rows in DataTable 14 shown in view after filter
applied. For any of the 14 how do I do the datarow or something else thing
to access the data in the row of the table behind the view selected on the
datagrid.

DataGrid only gives an index based on the 1-14 visible on the datagrid and I
can't seem to update anything I see in the dataview quickwatch that I can
update the underlying row. I could manually keep track of the index to the
datatable but if I could figure out how to update the table behind the
dataGrid index of the view without a lot of looping, comparing, etc.
 
T

Terry Olsen

I'm not sure I understand the question completely, but would using a DataSet
work for this?
Put the DataTables in a DataSet and then make the DataSet the source for the
DataGrid.
 
J

Jay B. Harlow [MVP - Outlook]

Richard,
I'm not following what you want?

A DataView is a "live" view into a DataTable.

Updating a row in a DataView updates the corresponding row in the DataTable.
As you know DataTable contains a collection of DataRow objects. The DataView
itself contains a collection of DataRowView objects. DataRowView has a Row
property that is the DataRow itself in the DataTable.

You really shouldn't need to track any indexes, as that is the DataView's
job.

Hope this helps
Jay

| Windows Forms, csharp, 20 rows in DataTable 14 shown in view after filter
| applied. For any of the 14 how do I do the datarow or something else thing
| to access the data in the row of the table behind the view selected on the
| datagrid.
|
| DataGrid only gives an index based on the 1-14 visible on the datagrid and
I
| can't seem to update anything I see in the dataview quickwatch that I can
| update the underlying row. I could manually keep track of the index to the
| datatable but if I could figure out how to update the table behind the
| dataGrid index of the view without a lot of looping, comparing, etc.
|
|
 
B

Bernie Yaeger

Hi Richard,

This isn't difficult. When you do a .find on a dataview, it returns the row
index. The following syntax enables you to update that very row, without
looping of any kind:
If ifind <> -1 Then ' ie, found it

dsprod.Tables(0).Rows(ifind)("copywt") = "abcd"

dsprod.Tables(0).Rows(ifind)("onsaledt") = CDate("05/10/2003")

End If

HTH,

Bernie Yaeger
 
R

Richard

Now that I learned the current row index of the data grid corresponds to the
DataRowView's copy of the bound data table's record, I think I can refine it
with the copywt code below. I use a single table which is not in a dataset
but I think it will still work.
 
B

Bernie Yaeger

Hi Richard,

Yes, it should, but if you have any questions, send me some code and I'll be
glad to look at it.

Bernie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top