Add UD child table (nothing populating)

I think I have resolved by using what you suggested I think I just needed to come out then back in.

I will resolve this post with the answer once I have confirmed. Thank you so much for your help.

If you could explain the use of the end of the where clause where it says “& key1” . Would like to understand what this does.

(in the following, lowercase references are for variables, Fist uppercase are for column or field names)

key1 is a variable which holds the current PartNum. Since your UD07 table stores the PartNum in field Key3, then UD07 records where Key3 = key1 are required.

So setting the whereClause to "Key3 = '" & key1 & "'" sets the criteria used for selecting records from UD07. If PartNum ABC-123 was loaded in the form, key1 would equal ABC-123. So the variable whereClause woud be assigned "Key3 = 'ABC-123'"

Thank you that makes sense.
Here is my code in case anyone else is having the same issue I had. I changed the set initial UD Key values, and altered the where clause. I am able to delete a record via delete button on keyboard.

' **************************************************
' Custom code for PartForm
' Created: 24/08/2017 11:05:45
' **************************************************
Imports System
Imports System.ComponentModel
Imports System.Data
Imports System.Diagnostics
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Imports Erp.Adapters
Imports Erp.UI
Imports Ice.Lib
Imports Ice.Adapters
Imports Ice.Lib.Customization
Imports Ice.Lib.ExtendedProps
Imports Ice.Lib.Framework
Imports Ice.Lib.Searches
Imports Ice.UI.FormFunctions

Module Script

	' ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	' Begin Wizard Added Module Level Variables **

	Private WithEvents _ud07Adapter As UD07Adapter
	Private _edvPart As EpiDataView
	Private UD07_Column As DataTable
	Private _edvUD07 As EpiDataView
	Private WithEvents _Key1UD07 As String
	Private WithEvents _Key2UD07 As String
	Private WithEvents _Key3UD07 As String
	Private WithEvents _Key4UD07 As String
	Private WithEvents _Key5UD07 As String
	Private WithEvents Part_DataView As DataView
	' End Wizard Added Module Level Variables **

	' Add Custom Module Level Variables Here **

	Public Sub InitializeCustomCode()
		' ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		' Begin Wizard Added Variable Initialization

		InitializeUD07Adapter()
		Script._Key1UD07 = String.Empty
		Script._Key2UD07 = String.Empty
		Script._Key3UD07 = String.Empty
		Script._Key4UD07 = String.Empty
		Script._Key5UD07 = String.Empty
		AddHandler Script.baseToolbarsManager.ToolClick, AddressOf Script.baseToolbarsManager_ToolClickForUD07
		AddHandler Script.PartForm.BeforeToolClick, AddressOf Script.PartForm_BeforeToolClickForUD07
		AddHandler Script.PartForm.AfterToolClick, AddressOf Script.PartForm_AfterToolClickForUD07
		AddHandler Script.Part_Row.EpiRowChanged, AddressOf Script.Part_AfterRowChangeForUD07
		Script.Part_DataView = Script.Part_Row.dataView
		AddHandler Script.Part_DataView.ListChanged, AddressOf Script.Part_DataView_ListChangedForUD07
		' End Wizard Added Variable Initialization

		' Begin Wizard Added Custom Method Calls

		' End Wizard Added Custom Method Calls
	End Sub

	Public Sub DestroyCustomCode()
		' ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		' Begin Wizard Added Object Disposal

		If (Not (Script._ud07Adapter) Is Nothing) Then
			Script._ud07Adapter.Dispose
			Script._ud07Adapter = Nothing
		End If
		Script._edvUD07 = Nothing
		Script._edvPart = Nothing
		Script.UD07_Column = Nothing
		Script._Key1UD07 = Nothing
		Script._Key2UD07 = Nothing
		Script._Key3UD07 = Nothing
		Script._Key4UD07 = Nothing
		Script._Key5UD07 = Nothing
		RemoveHandler Script.baseToolbarsManager.ToolClick, AddressOf Script.baseToolbarsManager_ToolClickForUD07
		RemoveHandler Script.PartForm.BeforeToolClick, AddressOf Script.PartForm_BeforeToolClickForUD07
		RemoveHandler Script.PartForm.AfterToolClick, AddressOf Script.PartForm_AfterToolClickForUD07
		RemoveHandler Script.Part_Row.EpiRowChanged, AddressOf Script.Part_AfterRowChangeForUD07
		RemoveHandler Script.Part_DataView.ListChanged, AddressOf Script.Part_DataView_ListChangedForUD07
		Script.Part_DataView = Nothing
		' End Wizard Added Object Disposal

		' Begin Custom Code Disposal

		' End Custom Code Disposal
	End Sub


	Private Sub InitializeUD07Adapter()
		' Create an instance of the Adapter.
		Script._ud07Adapter = New UD07Adapter(Script.oTrans)
		Script._ud07Adapter.BOConnect

		' Add Adapter Table to List of Views
		' This allows you to bind controls to the custom UD Table
		Script._edvUD07 = New EpiDataView()
		Script._edvUD07.dataView = New DataView(Script._ud07Adapter.UD07Data.UD07)
		Script._edvUD07.AddEnabled = true
		Script._edvUD07.AddText = "New UD07"
		If (Script.oTrans.EpiDataViews.ContainsKey("UD07View") = false) Then
			Script.oTrans.Add("UD07View", Script._edvUD07)
		End If

		' Initialize DataTable variable
		Script.UD07_Column = Script._ud07Adapter.UD07Data.UD07

		' Initialize EpiDataView field.
		Script._edvPart = CType(Script.oTrans.EpiDataViews("Part"),EpiDataView)

		' Set the parent view / keys for UD child view
		Dim parentKeyFields(0) As String
		Dim childKeyFields(0) As String
		parentKeyFields(0) = "PartNum"
		childKeyFields(0) = "Key3"
		Script._edvUD07.SetParentView(Script._edvPart, parentKeyFields, childKeyFields)

		If (Not (Script.oTrans.PrimaryAdapter) Is Nothing) Then
			' Script.oTrans.PrimaryAdapter.GetCurrentDataSet(Ice.Lib.Searches.DataSetMode.RowsDataSet).Tables.Add(Script._edvUD07.dataView.Table.Clone)
		End If

	End Sub

	Private Sub GetUD07Data(ByVal key1 As String, ByVal key2 As String, ByVal key3 As String, ByVal key4 As String, ByVal key5 As String)
		If (Script._Key1UD07 <> key1) Or (Script._Key2UD07 <> key2) Or (Script._Key3UD07 <> key3) Or (Script._Key4UD07 <> key4) Or (Script._Key5UD07 <> key5) Then
			' Build where clause for search.
			Dim whereClause As String = "Key3 = '"  & key1 & "'"
			Dim whereClauses As System.Collections.Hashtable = New System.Collections.Hashtable(1)
			whereClauses.Add("UD07", whereClause)

			' Call the adapter search.
			Dim searchOptions As SearchOptions = SearchOptions.CreateRuntimeSearch(whereClauses, DataSetMode.RowsDataSet)
			Script._ud07Adapter.InvokeSearch(searchOptions)

			If (Script._ud07Adapter.UD07Data.UD07.Rows.Count > 0) Then
				Script._edvUD07.Row = 0
			Else
				Script._edvUD07.Row = -1
			End If

			' Notify that data was updated.
			Script._edvUD07.Notify(New EpiNotifyArgs(Script.oTrans, Script._edvUD07.Row, Script._edvUD07.Column))

			' Set key fields to their new values.
			Script._Key1UD07 = key1
			Script._Key2UD07 = key2
			Script._Key3UD07 = key3
			Script._Key4UD07 = key4
			Script._Key5UD07 = key5
		End If
	End Sub

	Private Sub GetNewUD07Record()
		Dim parentViewRow As DataRow = Script._edvPart.CurrentDataRow
		'Check for existence of Parent Row.
		If (parentViewRow Is Nothing) Then
			Exit Sub
		End If
		If Script._ud07Adapter.GetaNewUD07 Then
			Dim partnum As String = parentViewRow("PartNum").ToString

			' Get unique row count id for Key5
			Dim rowCount As Integer = Script._ud07Adapter.UD07Data.UD07.Rows.Count
			Dim lineNum As Integer = rowCount
			Dim goodIndex As Boolean = false
			While (goodIndex = false)
				' Check to see if index exists
				Dim matchingRows() As DataRow = Script._ud07Adapter.UD07Data.UD07.Select("Key5 = '" & lineNum.ToString & "'")
				If (matchingRows.Length > 0) Then
					lineNum = (lineNum + 1)
				Else
					goodIndex = true
				End If
			End While

			' Set initial UD Key values
			Dim editRow As DataRow = Script._ud07Adapter.UD07Data.UD07.Rows((rowCount - 1))
			editRow.BeginEdit
			editRow("Key1") = String.Empty
			editRow("Key2") = String.Empty
			editRow("Key3") = partnum
			editRow("Key4") = String.Empty
			editRow("Key5") = String.Empty
			editRow.EndEdit

			' Notify that data was updated.
			Script._edvUD07.Notify(New EpiNotifyArgs(Script.oTrans, (rowCount - 1), Script._edvUD07.Column))
		End If
	End Sub

	Private Sub SaveUD07Record()
		' Save adapter data
		Script._ud07Adapter.Update
	End Sub

	Private Sub DeleteUD07Record()
		' Check to see if deleted view is ancestor view
		Dim isAncestorView As Boolean = false
		Dim parView As Ice.Lib.Framework.EpiDataView = Script._edvUD07.ParentView
		While (Not (parView) Is Nothing)
			If (Script.oTrans.LastView Is parView) Then
				isAncestorView = true
				Exit While
			Else
				parView = parView.ParentView
			End If
		End While

		' If Ancestor View then delete all child rows
		If isAncestorView Then
			Dim drsDeleted() As DataRow = Script._ud07Adapter.UD07Data.UD07.Select("Key1 = '" & Script._Key1UD07 & "' AND Key2 = '" & Script._Key2UD07 & "' AND Key3 = '" & Script._Key3UD07 & "' AND Key4 = '" & Script._Key4UD07 & "'")
			Dim i As Integer = 0
			Do While (i < drsDeleted.Length)
				Script._ud07Adapter.Delete(drsDeleted(i))
				i = (i + 1)
			Loop
		Else
			If (Script.oTrans.LastView Is Script._edvUD07) Then
				If (Script._edvUD07.Row >= 0) Then
					Dim drDeleted As DataRow = CType(Script._ud07Adapter.UD07Data.UD07.Rows(Script._edvUD07.Row),DataRow)
					If (Not (drDeleted) Is Nothing) Then
						If Script._ud07Adapter.Delete(drDeleted) Then
							If (_edvUD07.Row > 0) Then
								_edvUD07.Row = (_edvUD07.Row - 1)
							End If

							' Notify that data was updated.
							Script._edvUD07.Notify(New EpiNotifyArgs(Script.oTrans, Script._edvUD07.Row, Script._edvUD07.Column))
						End If
					End If
				End If
			End If
		End If
	End Sub

	Private Sub UndoUD07Changes()
		Script._ud07Adapter.UD07Data.RejectChanges

		' Notify that data was updated.
		Script._edvUD07.Notify(New EpiNotifyArgs(Script.oTrans, Script._edvUD07.Row, Script._edvUD07.Column))
	End Sub

	Private Sub ClearUD07Data()
		Script._Key1UD07 = String.Empty
		Script._Key2UD07 = String.Empty
		Script._Key3UD07 = String.Empty
		Script._Key4UD07 = String.Empty
		Script._Key5UD07 = String.Empty

		Script._ud07Adapter.UD07Data.Clear

		' Notify that data was updated.
		Script._edvUD07.Notify(New EpiNotifyArgs(Script.oTrans, Script._edvUD07.Row, Script._edvUD07.Column))
	End Sub

	Private Sub baseToolbarsManager_ToolClickForUD07(ByVal sender As Object, ByVal args As Infragistics.Win.UltraWinToolbars.ToolClickEventArgs)
		' EpiMessageBox.Show(args.Tool.Key)
		Select Case args.Tool.Key

			Case "EpiAddNewNew UD07"
				GetNewUD07Record

			Case "ClearTool"
				ClearUD07Data

			Case "UndoTool"
				UndoUD07Changes

		End Select
	End Sub

	Private Sub PartForm_BeforeToolClickForUD07(ByVal sender As Object, ByVal args As Ice.Lib.Framework.BeforeToolClickEventArgs)
		' EpiMessageBox.Show(args.Tool.Key)
		Select Case args.Tool.Key

			Case "SaveTool"
				SaveUD07Record

		End Select
	End Sub

	Private Sub PartForm_AfterToolClickForUD07(ByVal sender As Object, ByVal args As Ice.Lib.Framework.AfterToolClickEventArgs)
		' EpiMessageBox.Show(args.Tool.Key)
		Select Case args.Tool.Key

			Case "DeleteTool"
				If (args.Cancelled = false) Then
					DeleteUD07Record
				End If

		End Select
	End Sub

	Private Sub Part_AfterRowChangeForUD07(ByVal args As EpiRowChangedArgs)
		' ** add AfterRowChange event handler
		Dim partnum As String = args.CurrentView.dataView(args.CurrentRow)("PartNum").ToString
		GetUD07Data(partnum, String.Empty, String.Empty, String.Empty, String.Empty)
	End Sub

	Private Sub Part_DataView_ListChangedForUD07(ByVal sender As Object, ByVal args As ListChangedEventArgs)
		' ** add ListChanged event handler
		Dim partnum As String = Part_DataView(0)("PartNum").ToString
		GetUD07Data(partnum, String.Empty, String.Empty, String.Empty, String.Empty)
	End Sub
End Module
1 Like