|
-
May 1st, 2006, 03:13 AM
#1
Thread Starter
Member
Dataview confusion
Hi All,
I am new to VB.Net and I have noticed somthing strange with dataviews.
The code below does not move through the dataview but displays only the results for the first record.
VB Code:
For i = 0 To dv.Count - 1
'dv(i).BeginEdit()
Console.WriteLine(dv(i)("Machine") & ": " & dv(i)("Display"))
'dv(i).EndEdit()
Next
The code below shows all the details correctly.
VB Code:
Dim myDRV As DataRowView
For Each myDRV In dv
Console.WriteLine(myDRV("Machine") & ": " & myDRV("Display"))
Next
As I said I am new to VB.Net so if someone could point out my mistake it would be appreciated.
Regards,
Adam.
-
May 1st, 2006, 03:23 AM
#2
Re: Dataview confusion
You must be doing something else wrong because they both work for me.
-
May 1st, 2006, 03:30 AM
#3
Thread Starter
Member
Re: Dataview confusion
Thanks for replying, I am updating the rows on the first pass. When I move through the rows a second time it appears to get stuck on the first row.
I have tried using the 'BeginEdit' & 'EndEdit' during the update but they do not appear to fix the problem.
VB Code:
dv(i)("ActualDisplayOrder") = i + 1
etc....
Sorry I did not mention this, I thought I might have had the basic code incorrect.
Cheers,
Adam.
-
May 1st, 2006, 03:43 AM
#4
Re: Dataview confusion
I think you need to show the full code.
-
May 1st, 2006, 05:16 AM
#5
Thread Starter
Member
Re: Dataview confusion
Hi jmcilhinney,
The code I have inherited is shown below. The issue is when the aShow(i) is being loaded. 'dv(i)("Display")' gives the array the correct value the first time the procedure is run but after that the loop appears to get stuck on the first record. It is quite interesting as when I use a 'dataRow' to enumerate through the dataview it gives the correct values. I have tried using 'BeginEdit' & 'EndEdit' but it does not correct it. Maybe it is because I am using a filter & sorting. The dataview is getting updated but it gets stuck on the first records as noted above.
Any ideas would be appreciated ?
VB Code:
' Class variable
Public dsMch As New DataSet
Private Sub ChangeValue(ByVal blnUp As Boolean)
Dim aRow As DataRow
Dim dv As DataView
Dim iMax As Integer
Dim i As Integer
Dim aShow() As Boolean
Dim blnCurrentDisplay As Boolean
dv = New DataView(Me.dsMch.Tables(0))
dv.AllowEdit = True
dv.AllowDelete = False
dv.AllowNew = False
dv.RowFilter = "Display = True OR Source = 'Schedule'"
dv.Sort = "ActualDisplayOrder ASC"
ReDim aShow(dv.Count - 1)
If blnUp Then
' Increment ActualDispalyOrder
' Set all DisplayOrders to 999
For i = 0 To dv.Count - 1
'dv(i).BeginEdit()
dv(i)("DisplayOrder") = 999
Console.WriteLine(dv(i)("Machine") & ": " & dv(i)("Display"))
'**** Incorrect values when called more than once *****
aShow(i) = dv(i)("Display")
If i = dv.Count - 1 Then
' Set last value to zero
dv(i)("ActualDisplayOrder") = 0
Else
' Increment Actual display
dv(i)("ActualDisplayOrder") = i + 1
End If
'dv(i).EndEdit()
Next
Else
End If
' Sort by ActualDisplayOrder & set flag to show as
' per array
'dv.Sort = vbNullString
dv.Sort = "ActualDisplayOrder ASC"
For i = 0 To dv.Count - 1
dv(i).BeginEdit()
dv(i)("Display") = aShow(i)
dv(i).EndEdit()
Next
' Update display order used to show machines
dv.RowFilter = vbNullString
dv.RowFilter = "Display = True AND Source = 'Schedule'"
dv.Sort = "ActualDisplayOrder ASC"
For i = 0 To dv.Count - 1
dv(i).BeginEdit()
dv(i)("DisplayOrder") = i
dv(i).EndEdit()
Next
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|