It took me a while to figure this out, so I thought I would share it with everyone. The following code will copy the current row in a dataview (in this case UD105A) to a new row. It changes to ChildKey before it imports the new row so it doesn't violate key restraints.
Dim QuoteNum as String
Dim NextQuoteNum as Integer
Dim edvUD105A as EpiDataView = CType(oTrans.EpiDataViews("UD105A"), EpiDataView)
If (edvUD105A.HasRow) Then
Dim tblUD105a = edvUD105a.DataView.Table.Clone()
'// ** Make a copy of the current row **
tblUD105a.ImportRow(edvUD105A.DataView.Table.Rows(edvUD105A.Row))
'// ** Change ChildKey1 **
NextQuoteNum = 1
QuoteNum = edvUD105.dataview(edvUD105.Row)("Key2") & "-" & Right("0" & Now.Month(), 2) & Right("0" & Now.Day(), 2) & Right(Now.Year(), 2)
For Each Quote as DataRow in edvUD105a.Dataview.table.Rows
If (Left(Quote("ChildKey1"),Len(Quote("ChildKey1"))-4) = QuoteNum) AND (Val(Right(Quote("ChildKey1"),3)) >= NextQuoteNum) Then NextQuoteNum = Val(Right(Quote("ChildKey1"),3)) + 1
Next
tblUD105a.Rows(0)("ChildKey1") = QuoteNum & "-" & Right("00" & NextQuoteNum.ToString(), 3)
'// ** Clear Modified row state and then set row state to Added **
tblUD105a.Rows(0).AcceptChanges()
tblUD105a.Rows(0).SetAdded()
'// ** Import import copied row to table **
edvUD105A.DataView.Table.ImportRow(tblUD105a.Rows(0))
'// ** Save table with new row added **
Otrans.Update()
otrans.Refresh()
'// ** Make new row active
edvUD105A.Row = (edvUD105A.DataView.Count-1)
End If
Steven G.
Dim QuoteNum as String
Dim NextQuoteNum as Integer
Dim edvUD105A as EpiDataView = CType(oTrans.EpiDataViews("UD105A"), EpiDataView)
If (edvUD105A.HasRow) Then
Dim tblUD105a = edvUD105a.DataView.Table.Clone()
'// ** Make a copy of the current row **
tblUD105a.ImportRow(edvUD105A.DataView.Table.Rows(edvUD105A.Row))
'// ** Change ChildKey1 **
NextQuoteNum = 1
QuoteNum = edvUD105.dataview(edvUD105.Row)("Key2") & "-" & Right("0" & Now.Month(), 2) & Right("0" & Now.Day(), 2) & Right(Now.Year(), 2)
For Each Quote as DataRow in edvUD105a.Dataview.table.Rows
If (Left(Quote("ChildKey1"),Len(Quote("ChildKey1"))-4) = QuoteNum) AND (Val(Right(Quote("ChildKey1"),3)) >= NextQuoteNum) Then NextQuoteNum = Val(Right(Quote("ChildKey1"),3)) + 1
Next
tblUD105a.Rows(0)("ChildKey1") = QuoteNum & "-" & Right("00" & NextQuoteNum.ToString(), 3)
'// ** Clear Modified row state and then set row state to Added **
tblUD105a.Rows(0).AcceptChanges()
tblUD105a.Rows(0).SetAdded()
'// ** Import import copied row to table **
edvUD105A.DataView.Table.ImportRow(tblUD105a.Rows(0))
'// ** Save table with new row added **
Otrans.Update()
otrans.Refresh()
'// ** Make new row active
edvUD105A.Row = (edvUD105A.DataView.Count-1)
End If
Steven G.