LEADTOOLS Medical (Leadtools.Dicom assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
SetValue Method
See Also 
Leadtools.Dicom Namespace > DicomDataSet Class : SetValue Method



element
An item in the Data Set.
value
>An System.Object that can be any supported type, or an array of any supported type.
element
An item in the Data Set.
value
>An System.Object that can be any supported type, or an array of any supported type.
Sets the value(s) of a Data Element. The value can be any supported type. Supported in Silverlight, Windows Phone 7.

Syntax

Visual Basic (Declaration) 
Public Function SetValue( _
   ByVal element As DicomElement, _
   ByVal value As Object _
) As Boolean
Visual Basic (Usage)Copy Code
Dim instance As DicomDataSet
Dim element As DicomElement
Dim value As Object
Dim value As Boolean
 
value = instance.SetValue(element, value)
C# 
public bool SetValue( 
   DicomElement element,
   object value
)
C++/CLI 
public:
bool SetValue( 
   DicomElement^ element,
   Object^ value
) 

Parameters

element
An item in the Data Set.
value
>An System.Object that can be any supported type, or an array of any supported type.

Return Value

true if the object value was set successfully. false if could not set the object value of the Data Element.

Example

This example shows how to set the value of various DICOM elements, regardless of the regardless of the DicomVRType or the multiplicity.

Visual BasicCopy Code
''' 
Private Function MyInsertElement(ByVal ds As DicomDataSet, ByVal tag As Long) As DicomElement
   Dim myTag As DicomTag = DicomTagTable.Instance.Find(tag)
   Dim element As DicomElement = ds.InsertElement(Nothing, False, tag, myTag.VR, False, 0)
   Return element
End Function
Private Sub DicomDataSet_SetValueExample()
   Dim element As DicomElement = Nothing
   Dim ds As DicomDataSet = New DicomDataSet()

   ' Set a string
   element = MyInsertElement(ds, DicomTag.PatientName)
   ds.SetValue(element, "Joe^Patient")

   ' Set an array of strings
   element = MyInsertElement(ds, DicomTag.OtherPatientNames)
   Dim names As String() = {"One", "Two", "Three"}
   ds.SetValue(element, names)

   ' Another way to do an array of strings
   Dim it As List(Of String) = New List(Of String)()
   it.Add("ORIGINAL")
   it.Add("PRIMARY")
   element = MyInsertElement(ds, DicomTag.ImageType)
   ds.SetValue(element, it.ToArray())

   ' Set an array of integers, that will be converted to strings
   element = MyInsertElement(ds, DicomTag.PhysicianOfRecord)
   Dim namesInt As Integer() = {1, 2, 3}
   ds.SetValue(element, namesInt)

   ' Set a DicomDateValue
   element = MyInsertElement(ds, DicomTag.PatientBirthDate)
   Dim dicomDate As DicomDateValue = New DicomDateValue(1961, 6, 5)
   ds.SetValue(element, dicomDate)

   ' Set a DateTime
   element = MyInsertElement(ds, DicomTag.InstanceCreationDate)
   Dim dateTime As DateTime = New DateTime(2003, 5, 16)
   ds.SetValue(element, dateTime)

   ' Set an array of DateTime
   element = MyInsertElement(ds, DicomTag.DateOfLastCalibration)
   Dim dateTimeArray As DateTime() = {New DateTime(2000, 3, 8), New DateTime(2003, 5, 16)}
   ds.SetValue(element, dateTimeArray)

   ds.Save(LeadtoolsExamples.Common.ImagesPath.Path + "test.dcm", DicomDataSetSaveFlags.None)
End Sub
C#Copy Code
/// 
private DicomElement MyInsertElement(DicomDataSet ds, long tag)
{
   DicomTag myTag = DicomTagTable.Instance.Find(tag);
   DicomElement element = ds.InsertElement(null, false, tag, myTag.VR, false, 0);
   return element;
}
private void DicomDataSet_SetValueExample()
{
   DicomElement element = null;
   DicomDataSet ds = new DicomDataSet();

   // Set a string
   element = MyInsertElement(ds, DicomTag.PatientName);
   ds.SetValue(element, "Joe^Patient");

   // Set an array of strings
   element = MyInsertElement(ds, DicomTag.OtherPatientNames);
   string[] names = { "One", "Two", "Three" };
   ds.SetValue(element, names);

   // Another way to do an array of strings
   List<string> it = new List<string>();
   it.Add("ORIGINAL");
   it.Add("PRIMARY");
   element = MyInsertElement(ds, DicomTag.ImageType);
   ds.SetValue(element, it.ToArray());

   // Set an array of integers, that will be converted to strings
   element = MyInsertElement(ds, DicomTag.PhysicianOfRecord);
   int[] namesInt = { 1, 2, 3 };
   ds.SetValue(element, namesInt);

   // Set a DicomDateValue
   element = MyInsertElement(ds, DicomTag.PatientBirthDate);
   DicomDateValue dicomDate = new DicomDateValue(1961, 6, 5);
   ds.SetValue(element, dicomDate);

   // Set a DateTime
   element = MyInsertElement(ds, DicomTag.InstanceCreationDate);
   DateTime dateTime = new DateTime(2003, 5, 16);
   ds.SetValue(element, dateTime);

   // Set an array of DateTime
   element = MyInsertElement(ds, DicomTag.DateOfLastCalibration);
   DateTime[] dateTimeArray = { new DateTime(2000, 3, 8), new DateTime(2003, 5, 16) };
   ds.SetValue(element, dateTimeArray);

   ds.Save(LeadtoolsExamples.Common.ImagesPath.Path + "test.dcm", DicomDataSetSaveFlags.None);
}
SilverlightCSharpCopy Code
private DicomElement MyInsertElement(DicomDataSet ds, long tag)
{
   DicomTag myTag = DicomTagTable.Instance.Find(tag);
   DicomElement element = ds.InsertElement(null, false, tag, myTag.VR, false, 0);
   return element;
}
private void DicomDataSet_SetValueExample(Stream outputStream)
{
   DicomElement element = null;
   DicomDataSet ds = new DicomDataSet();

   // Set a string
   element = MyInsertElement(ds, DicomTag.PatientName);
   ds.SetValue(element, "Joe^Patient");

   // Set an array of strings
   element = MyInsertElement(ds, DicomTag.OtherPatientNames);
   string[] names = { "One", "Two", "Three" };
   ds.SetValue(element, names);

   // Another way to do an array of strings
   List<string> it = new List<string>();
   it.Add("ORIGINAL");
   it.Add("PRIMARY");
   element = MyInsertElement(ds, DicomTag.ImageType);
   ds.SetValue(element, it.ToArray());

   // Set an array of integers, that will be converted to strings
   element = MyInsertElement(ds, DicomTag.PhysicianOfRecord);
   int[] namesInt = { 1, 2, 3 };
   ds.SetValue(element, namesInt);

   // Set a DicomDateValue
   element = MyInsertElement(ds, DicomTag.PatientBirthDate);
   DicomDateValue dicomDate = new DicomDateValue(1961, 6, 5);
   ds.SetValue(element, dicomDate);

   // Set a DateTime
   element = MyInsertElement(ds, DicomTag.InstanceCreationDate);
   DateTime dateTime = new DateTime(2003, 5, 16);
   ds.SetValue(element, dateTime);

   // Set an array of DateTime
   element = MyInsertElement(ds, DicomTag.DateOfLastCalibration);
   DateTime[] dateTimeArray = { new DateTime(2000, 3, 8), new DateTime(2003, 5, 16) };
   ds.SetValue(element, dateTimeArray);

   ds.Save(outputStream, DicomDataSetSaveFlags.None);
}
SilverlightVBCopy Code
Private Function MyInsertElement(ByVal ds As DicomDataSet, ByVal tag As Long) As DicomElement
   Dim myTag As DicomTag = DicomTagTable.Instance.Find(tag)
   Dim element As DicomElement = ds.InsertElement(Nothing, False, tag, myTag.VR, False, 0)
   Return element
End Function
Private Sub DicomDataSet_SetValueExample(ByVal outputStream As Stream)
   Dim element As DicomElement = Nothing
   Dim ds As DicomDataSet = New DicomDataSet()

   ' Set a string
   element = MyInsertElement(ds, DicomTag.PatientName)
   ds.SetValue(element, "Joe^Patient")

   ' Set an array of strings
   element = MyInsertElement(ds, DicomTag.OtherPatientNames)
   Dim names As String() = {"One", "Two", "Three"}
   ds.SetValue(element, names)

   ' Another way to do an array of strings
   Dim it As List(Of String) = New List(Of String)()
   it.Add("ORIGINAL")
   it.Add("PRIMARY")
   element = MyInsertElement(ds, DicomTag.ImageType)
   ds.SetValue(element, it.ToArray())

   ' Set an array of integers, that will be converted to strings
   element = MyInsertElement(ds, DicomTag.PhysicianOfRecord)
   Dim namesInt As Integer() = {1, 2, 3}
   ds.SetValue(element, namesInt)

   ' Set a DicomDateValue
   element = MyInsertElement(ds, DicomTag.PatientBirthDate)
   Dim dicomDate As DicomDateValue = New DicomDateValue(1961, 6, 5)
   ds.SetValue(element, dicomDate)

   ' Set a DateTime
   element = MyInsertElement(ds, DicomTag.InstanceCreationDate)
   Dim dateTime As DateTime = New DateTime(2003, 5, 16)
   ds.SetValue(element, dateTime)

   ' Set an array of DateTime
   element = MyInsertElement(ds, DicomTag.DateOfLastCalibration)
   Dim dateTimeArray As DateTime() = {New DateTime(2000, 3, 8), New DateTime(2003, 5, 16)}
   ds.SetValue(element, dateTimeArray)

   ds.Save(outputStream, DicomDataSetSaveFlags.None)
End Sub

Remarks

Note: The user is responsible to allocate the memory for value.

This is very flexible function that can be used to set the value of almost any DICOM data element, regardless of the DicomVRType The System.Object can be any of the following:

Requirements

Target Platforms: Silverlight 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)

See Also

Leadtools.Dicom requires a Medical toolkit server license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features