InsertIOD Example for VB.NET

'LEADDICOM1 is a DICOM Dataset defined outside this method
Private Sub TestInsertIOD(bChild As Boolean)
   Dim bInsert As Boolean
   Dim lCode As Integer
   Dim nType As Short
   Dim hIOD As Integer
   Dim hTemp As Integer
   Dim nRet As Short

   bInsert = False

   LEADDICOM1.EnableMethodErrors = True

On Error GoTo INSERTIODERROR

   lCode = 1048593
   nType = LTDICLib.DicomIODTypeConstants.DICOM_IOD_TYPE_CLASS
   'store current IOD
   hIOD = LEADDICOM1.CurrentIOD.hIOD

   LEADDICOM1.EnableMethodErrors = False

   'does an IOD already exist on the target level?
   If (bChild = True) Then
      'if the current IOD has a child, move to that child's level
      nRet = LEADDICOM1.MoveChildIOD
      If (nRet <> 0) Then
         'no children, so insert is OK
         bInsert = True
         LEADDICOM1.SetCurrentIOD(hIOD)
      Else
         'check the child's level to see if target IOD already exists
         hTemp = LEADDICOM1.CurrentIOD.hIOD
         LEADDICOM1.MoveFirstIOD(True)
         nRet = LEADDICOM1.FindIOD(lCode, nType, True)
         If (nRet <> 0) Then
            bInsert = True
         End If
         'move back to parent level
         LEADDICOM1.SetCurrentIOD(hTemp)
         LEADDICOM1.MoveParentIOD()
      End If
   Else
      'check the current IOD's level
      LEADDICOM1.MoveFirstIOD(True)
      nRet = LEADDICOM1.FindIOD(lCode, nType, True)
      If (nRet <> 0) Then
         bInsert = True
      End If
      LEADDICOM1.SetCurrentIOD(hIOD)
   End If

   LEADDICOM1.EnableMethodErrors = True

   'allow user to insert item at the same level as the current or as child
   If (bInsert = True) Then
      LEADDICOM1.InsertIOD(bChild, nType, lCode, "My Test IOD", 5, "Test Description")
   Else
      MessageBox.Show("Already exists")
   End If
   Exit Sub

INSERTIODERROR:
   MessageBox.Show("Error")

LEADDICOM1.EnableMethodErrors = True

End Sub