InsertKey Example for VB.NET

'LEADDICOM1 is a DICOM Dataset defined outside this method
Private Sub TestInsertKey ()
   Dim x As Short

   LEADDICOM1.ResetDS()
   LEADDICOM1.InitDS(LTDICLib.DicomClassConstants.DICOM_CLASS_UNKNOWN, 0)

   'insert some keys
   LEADDICOM1.InsertKey("PATIENT", True)
   'insert PATIENT level key
   LEADDICOM1.InsertKey("STUDY", True)
   'insert STUDY level key

   'insert 5 SERIES level keys and some data
   For x = 1 To 5
      LEADDICOM1.StringValueCount  = 1
      LEADDICOM1.InsertKey("SERIES", True)
      LEADDICOM1.MoveChildElement()
      LEADDICOM1.FindFirstElement(LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID, True)
      LEADDICOM1.StringValues(0) = CStr(x)
      LEADDICOM1.SetStringValue(1)
      LEADDICOM1.MoveParentElement()
      LEADDICOM1.MoveParentKey()
      'move back up one level
   Next

   'move to root key
   LEADDICOM1.MoveRootKey()
   'PATIENT level
   MessageBox.Show(LEADDICOM1.GetKeyValue)

   'move to SERIES level
   LEADDICOM1.MoveChildKey()
   'STUDY
   LEADDICOM1.MoveChildKey()
   'SERIES

   'find first SERIES
   LEADDICOM1.FindFirstKey("SERIES", True)
   LEADDICOM1.MoveChildElement()
   LEADDICOM1.FindFirstElement(LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID, True)
   LEADDICOM1.GetStringValue(0, 1)
   MessageBox.Show(LEADDICOM1.StringValues(0))

   'find next series
   LEADDICOM1.FindNextKey(True)
   LEADDICOM1.MoveChildElement()
   LEADDICOM1.FindFirstElement(LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID, True)
   LEADDICOM1.GetStringValue(0, 1)
   MessageBox.Show(LEADDICOM1.StringValues(0))

   'find last SERIES
   LEADDICOM1.FindLastKey("SERIES", True)
   LEADDICOM1.MoveChildElement()
   LEADDICOM1.FindFirstElement(LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID, True)
   LEADDICOM1.GetStringValue(0, 1)
   MessageBox.Show(LEADDICOM1.StringValues(0))

   'find previous SERIES
   LEADDICOM1.FindPrevKey(True)
   LEADDICOM1.MoveChildElement()
   LEADDICOM1.FindFirstElement(LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID, True)
   LEADDICOM1.GetStringValue(0, 1)
   MessageBox.Show(LEADDICOM1.StringValues(0))

   'find last SERIES and delete it
   LEADDICOM1.FindLastKey("SERIES", True)
   LEADDICOM1.DeleteKey()

   'move to root key
   LEADDICOM1.MoveFirstKey(False)
   MessageBox.Show(LEADDICOM1.GetKeyValue)

   'move to SERIES level
   LEADDICOM1.MoveChildKey()
   'STUDY
   LEADDICOM1.MoveChildKey()
   'SERIES

   'move to first SERIES
   LEADDICOM1.MoveFirstKey(True)
   LEADDICOM1.MoveChildElement()
   LEADDICOM1.FindFirstElement(LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID, True)
   LEADDICOM1.GetStringValue(0, 1)
   MessageBox.Show(LEADDICOM1.StringValues(0))

   'move to next series
   LEADDICOM1.MoveNextKey(True)
   LEADDICOM1.MoveChildElement()
   LEADDICOM1.FindFirstElement(LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID, True)
   LEADDICOM1.GetStringValue(0, 1)
   MessageBox.Show(LEADDICOM1.StringValues(0))

   'move to last SERIES
   LEADDICOM1.MoveLastKey(True)
   LEADDICOM1.MoveChildElement()
   LEADDICOM1.FindFirstElement(LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID, True)
   LEADDICOM1.GetStringValue(0, 1)
   MessageBox.Show(LEADDICOM1.StringValues(0))

   'move to previous SERIES
   LEADDICOM1.MovePrevKey(True)
   LEADDICOM1.MoveChildElement()
   LEADDICOM1.FindFirstElement(LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID, True)
   LEADDICOM1.GetStringValue(0, 1)
   MessageBox.Show(LEADDICOM1.StringValues(0))
End Sub