INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

DataView: loop through columns

DataView: loop through columns

(OP)
OK.  After two hours on Google I can not find an example to loop through a DataView the way I want to.  Maybe its got something to do with Monday morning.  Well, here is what I what to do:

For each row in dataview
For each col in dataview
debug.writeline(the current column)
Next
Next

Any suggestions?

RE: DataView: loop through columns

Without testing it I guess it would be something like:

CODE

        For Each dr As DataRow In dv.Table.Rows
            For i = 1 To dv.Table.Columns.Count
                Console.WriteLine(dr.Item(i))
            Next
            i = 1
        Next


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

RE: DataView: loop through columns

(OP)
Thank you, but I must ask this question: Why is it that when i type "dv." the only option intellisense gives me is "GetType"?  Why don't I see "Table"?

RE: DataView: loop through columns

Have you declared dv as DataView - or better still replace dv with the name of your DataView.


Hope this helps.

RE: DataView: loop through columns

(OP)
Here is the exact code:

CODE

Dim dvPartsPricing As DataView
dvPartsPricing = dsPartsPricing.Tables(0).DefaultView
dvPartsPricing.Sort = "CatMainSubGID, Length"

RE: DataView: loop through columns

To correctly navigate DataViews you need to use the DatarowView.

CODE

Dim dv As DataView = dt.DefaultView
dv.Sort = "field1,field2"

For Each rv As DataRowView In dv
    'Get the Datarow
    Dim r As DataRow = rv.Row
    For i As Integer = 0 To r.ItemArray.Length - 1
       Debug.WriteLine(r(i))
    Next
Next

Sweep
...if it works dont f*** with it

RE: DataView: loop through columns

(OP)
SqueakinSweep, what makes this the "correct" way?

RE: DataView: loop through columns

(OP)
ca8msm,

No matter what I tried, I could not get anything but "GetType" to show in intellisense.  BUT, this morning, after re-boot the computer, I get the full list of intellisense properties and methods.  Mmmmm....... Maybe a problem with my Visual Studio 2003.

Anyways, thanks again for the help, and what do you think of SqueakinSweep suggestions that there is a "correct" way to do this?  I like your solution; its simple and straight-forward.

RE: DataView: loop through columns

I would imagine that Sweep is correct. It makes sense that each row that you loop through should be a DataRowView rather than a DataRow.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

RE: DataView: loop through columns

It is the correct way, because if you use dv.table, you are referencing the datatable, and you lose the sort order which was the whole point of the view in the first place.

The code I provided is the for each mathod of skipping through a dataview

Sweep
...if it works dont f*** with it

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close