The problem I am having is that I am using a filtered dataview in a datagrid. It is filtered on a yes/no column called printed. Eventually the user highlights the rows they want to print and clicks the print button. First this clears the print dataset then causes the highlighted rows to be written to the print dataset, that part works fine. After that is done I want to mark the printed as yes in all the rows that have been printed. Unfortunately as soon as you mark the yes/no printed it filters it out causing the for loop to lose it place which means it either starts marking the wrong row or go outside the bounds of the dataview causing an error. I have tried unfiltering the dataview before I start the print process but that causes the rows highlighted by the user to become unhighlighted. The reason I'm putting the choices into an arraylist and doing the later is for the same reason.
Here is how the datagrid is setup with the dataview and filter.
forwardinglisttempset = New DataSet
flda.Fill(forwardinglistte
mpset)
forwardinglistgrid.DataSou
rce = forwardinglisttempset.Tabl
es(0)
forwardinglistview = New DataView(forwardinglistgri
d.DataSour
ce)
forwardinglistgrid.DataSou
rce = forwardinglistview
flda.TableMappings.Clear()
flda.TableMappings.Add("fo
rwardingli
sttempset.
Tables(0)"
, "forwardinglistview")
Dim command_builder = New Odbc.OdbcCommandBuilder(fl
da)
forwardinglistview.RowFilt
er = "printed = " & False
Here is the code that is activated when the print button is clicked:
Try
'setup
Dim marked As New ArrayList
Flprintds1.Clear()
flprintda.Fill(Flprintds1)
Dim command_builder = New Odbc.OdbcCommandBuilder(fl
printda)
'delete current print record
For Each tr As DataRow In Flprintds1.Tables(0).Rows
tr.Delete()
Next
'add highlighted rows for printing
For i As Integer = 0 To forwardinglistview.Count - 1
If forwardinglistgrid.IsSelec
ted(i) Then
rowTemp = Flprintds1.Tables(0).NewRo
w()
rowTemp.Item("trackingnumb
er") = fis(forwardinglistgrid.Ite
m(i, 1).ToString)
rowTemp.Item("lastname") = fis(forwardinglistgrid.Ite
m(i, 2).ToString)
rowTemp.Item("firstname") = fis(forwardinglistgrid.Ite
m(i, 3).ToString)
rowTemp.Item("middlename")
= fis(forwardinglistgrid.Ite
m(i, 4).ToString)
rowTemp.Item("address1") = fis(forwardinglistgrid.Ite
m(i, 9).ToString)
rowTemp.Item("address2") = fis(forwardinglistgrid.Ite
m(i, 10).ToString)
rowTemp.Item("city") = fis(forwardinglistgrid.Ite
m(i, 11).ToString)
rowTemp.Item("state") = fis(forwardinglistgrid.Ite
m(i, 12).ToString)
rowTemp.Item("zip") = fis(forwardinglistgrid.Ite
m(i, 13).ToString)
rowTemp.Item("country") = fis(forwardinglistgrid.Ite
m(i, 14).ToString)
'add printed rows to be marked later
marked.Add(forwardinglistg
rid.Item(i
, 1))
Flprintds1.Tables(0).Rows.
Add(rowTem
p)
End If
Next
'mark highlighted rows as printed
For i As Integer = 0 To marked.Count - 1
forwardinglistgrid.Item(ma
rked(i), 15) = True
Next
'instert empties for blanks on label sheet
For j As Integer = 1 To empties.Text
rowTemp = Flprintds1.Tables(0).NewRo
w()
rowTemp.Item("trackingnumb
er") = Format(Date.Now, "yyyyMMddHHmmssfffffff") & j
Flprintds1.Tables(0).Rows.
Add(rowTem
p)
Next
'update the print table in the database
flprintda.Update(Flprintds
1)
'activate the print macro in the database DEACTIVATED FOR TESTING
'RunMacro("printforwrdingl
istreport"
)
showforwardgrid()
Catch ex As Exception
errorwrite(ex.ToString)
End Try
Start Free Trial