InsertVR Example for C#

//This example uses the predefined variable “ListView1” of type “ListView” from “.NET Framework”.
//LEADDICOM1 is a DICOM Dataset defined outside this method
private void TestInsertVR()
{
   short nRet = 0;
   ListViewItem ItemX = null;
   short nCode = 0;
   short nRestrict = 0;
   LEADDICOM1.EnableMethodErrors = true;
   try
   {
      LEADDICOM1.EnableMethodErrors = false;
      nCode = 20322;
      nRet = LEADDICOM1.FindVR(nCode);
      if (nRet == 0)
      {
         MessageBox.Show("Already Exists!");
         return;
      }
      nRestrict = (short)LTDICLib.DicomVRRestrictionConstants.DICOM_VR_FIXED + (short)LTDICLib.DicomVRRestrictionConstants.DICOM_VR_TEXT;
      nRet = LEADDICOM1.InsertVR(nCode, "My Test VR", 64, nRestrict, 1);
      if (nRet != 0)
         MessageBox.Show("Error");
      //add item to the ListView control
      ItemX = ListView1.Items.Add(new ListViewItem());
      ItemX.Text = System.Convert.ToString(LEADDICOM1.get_CurrentVR().Code);
      ItemX.SubItems.Add(LEADDICOM1.get_CurrentVR().Name);
      ItemX.SubItems.Add(System.Convert.ToString(LEADDICOM1.get_CurrentVR().Length));
      ItemX.SubItems.Add(System.Convert.ToString(LEADDICOM1.get_CurrentVR().Restrict));
      ItemX.SubItems.Add(System.Convert.ToString(LEADDICOM1.get_CurrentVR().UnitSize));
      ItemX.Selected = true;
      ListView1.Refresh();
      ListView1.Focus();
      LEADDICOM1.EnableMethodErrors = true;
   }
   catch
   {
      MessageBox.Show("Error");
   }
}