Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
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 now!
  • 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.

ispeaker (Programmer) (OP)
9 Jan 06 12:18
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?
ca8msm (Programmer)
9 Jan 06 13:54
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.

ispeaker (Programmer) (OP)
9 Jan 06 14:52
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"?
earthandfire (Programmer)
9 Jan 06 16:01
Have you declared dv as DataView - or better still replace dv with the name of your DataView.


Hope this helps.

ispeaker (Programmer) (OP)
9 Jan 06 16:08
Here is the exact code:

CODE

Dim dvPartsPricing As DataView
dvPartsPricing = dsPartsPricing.Tables(0).DefaultView
dvPartsPricing.Sort = "CatMainSubGID, Length"
SqueakinSweep (Programmer)
10 Jan 06 5:31
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

ispeaker (Programmer) (OP)
10 Jan 06 11:26
SqueakinSweep, what makes this the "correct" way?
ispeaker (Programmer) (OP)
10 Jan 06 11:30
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.
ca8msm (Programmer)
10 Jan 06 11:34
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.

SqueakinSweep (Programmer)
11 Jan 06 8:09
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!

Back To Forum

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