InsertKey Example for C#
//LEADDICOM1 is a DICOM Dataset defined outside this method
private void TestInsertKey ( )
{
short x = 0;
LEADDICOM1.ResetDS();
LEADDICOM1.InitDS((int)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; x <= 5; x++)
{
LEADDICOM1.StringValueCount
= 1;
LEADDICOM1.InsertKey("SERIES",
true);
LEADDICOM1.MoveChildElement();
LEADDICOM1.FindFirstElement((int)LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID,
true);
LEADDICOM1.set_StringValues(0,System.Convert.ToString(x));
LEADDICOM1.SetStringValue(1);
LEADDICOM1.MoveParentElement();
LEADDICOM1.MoveParentKey();
//move back up one level
}
//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((int)LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID,
true);
LEADDICOM1.GetStringValue(0,
1);
MessageBox.Show(LEADDICOM1.get_StringValues(0));
//find next series
LEADDICOM1.FindNextKey(true);
LEADDICOM1.MoveChildElement();
LEADDICOM1.FindFirstElement((int)LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID,
true);
LEADDICOM1.GetStringValue(0,
1);
MessageBox.Show(LEADDICOM1.get_StringValues(0));
//find last SERIES
LEADDICOM1.FindLastKey("SERIES",
true);
LEADDICOM1.MoveChildElement();
LEADDICOM1.FindFirstElement((int)LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID,
true);
LEADDICOM1.GetStringValue(0,
1);
MessageBox.Show(LEADDICOM1.get_StringValues(0));
//find previous SERIES
LEADDICOM1.FindPrevKey(true);
LEADDICOM1.MoveChildElement();
LEADDICOM1.FindFirstElement((int)LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID,
true);
LEADDICOM1.GetStringValue(0,
1);
MessageBox.Show(LEADDICOM1.get_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((int)LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID,
true);
LEADDICOM1.GetStringValue(0,
1);
MessageBox.Show(LEADDICOM1.get_StringValues(0));
//move to next series
LEADDICOM1.MoveNextKey(true);
LEADDICOM1.MoveChildElement();
LEADDICOM1.FindFirstElement((int)LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID,
true);
LEADDICOM1.GetStringValue(0,
1);
MessageBox.Show(LEADDICOM1.get_StringValues(0));
//move to last SERIES
LEADDICOM1.MoveLastKey(true);
LEADDICOM1.MoveChildElement();
LEADDICOM1.FindFirstElement((int)LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID,
true);
LEADDICOM1.GetStringValue(0,
1);
MessageBox.Show(LEADDICOM1.get_StringValues(0));
//move to previous SERIES
LEADDICOM1.MovePrevKey(true);
LEADDICOM1.MoveChildElement();
LEADDICOM1.FindFirstElement((int)LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_FILE_ID,
true);
LEADDICOM1.GetStringValue(0,
1);
MessageBox.Show(LEADDICOM1.get_StringValues(0));
}