PC Review


Reply
Thread Tools Rate Thread

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

 
 
Richard
Guest
Posts: n/a
 
      16th Jul 2005
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.


 
Reply With Quote
 
 
 
 
Terry Olsen
Guest
Posts: n/a
 
      16th Jul 2005
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.

"Richard" <(E-Mail Removed)> wrote in message
news:NFYBe.744$(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      16th Jul 2005
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

"Richard" <(E-Mail Removed)> wrote in message
news:NFYBe.744$(E-Mail Removed)...
| 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.
|
|


 
Reply With Quote
 
Bernie Yaeger
Guest
Posts: n/a
 
      16th Jul 2005
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



"Richard" <(E-Mail Removed)> wrote in message
news:NFYBe.744$(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      17th Jul 2005
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.

"Bernie Yaeger" <(E-Mail Removed)> wrote in message
news:ur%(E-Mail Removed)...
> 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
>
>
>
> "Richard" <(E-Mail Removed)> wrote in message
> news:NFYBe.744$(E-Mail Removed)...
> > 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.
> >
> >

>
>



 
Reply With Quote
 
Bernie Yaeger
Guest
Posts: n/a
 
      17th Jul 2005
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

"Richard" <(E-Mail Removed)> wrote in message
news:zuuCe.5100$(E-Mail Removed)...
> 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.
>
> "Bernie Yaeger" <(E-Mail Removed)> wrote in message
> news:ur%(E-Mail Removed)...
>> 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
>>
>>
>>
>> "Richard" <(E-Mail Removed)> wrote in message
>> news:NFYBe.744$(E-Mail Removed)...
>> > 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.
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataTable -> DataView -> Sort -> DataGrid : need related DataTable index Diamonds Microsoft ADO .NET 4 28th Jun 2006 08:23 PM
DataView - How to access the row in the datatable behind the DataView Richard Microsoft C# .NET 5 17th Jul 2005 04:57 PM
How to assign the changed datatable in dataview back to a datatable? TaeHo Yoo Microsoft C# .NET 1 8th Jul 2005 04:41 AM
Is there an easy way to copy a DataView (or even the DataGrid showing the DataView) to the Clipboard? Kevin Brown Microsoft Dot NET 4 5th Jan 2005 09:01 PM
Does DataView(DataTable) constructor just return DataTable.DefaultView? Neil Price Microsoft ADO .NET 1 22nd Sep 2003 12:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:22 PM.