InsertTag 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 TestInsertTag ( )
{
   try
   {
      short nRet = 0;
      ListViewItem ItemX = null;
      string szItem = null;
      int nLen = 0;
      int x = 0;
      string szItemL = null;
      string szItemR = null;
      LEADDICOM1.EnableMethodErrors = false;
      nRet = LEADDICOM1.FindTag(131079);
      if (nRet == 0)
      {
         MessageBox.Show("Already Exists!");
         return;
      }
      nRet = LEADDICOM1.InsertTag(131079, -1, "My Test Tag", (short)LTDICLib.DicomVRCodeConstants.VR_OB, 1, 1, 1);
      if (nRet != 0)
         MessageBox.Show("Error");
      LEADDICOM1.EnableMethodErrors = true;
      //add item to the ListView control
      ItemX = new ListViewItem();
      ListView1.Items.Add(ItemX);
      szItem = System.Convert.ToString(LEADDICOM1.get_CurrentTag().Code, 16).ToUpper();
      nLen = szItem.Length;
      szItemR = szItem.Substring(szItem.Length - 4);
      szItemL = "";
      for (x = nLen; x <= 7; x++)
      {
         szItemL = szItemL + System.Convert.ToString(0);
      }
      szItemL = szItemL + szItem.Substring(0, nLen - 4);
      ItemX.Text = szItemL + ":" + szItemR;
      szItem = System.Convert.ToString(LEADDICOM1.get_CurrentTag().Mask, 16).ToUpper();
      nLen = szItem.Length;
      szItemR = szItem.Substring(szItem.Length - 4);
      szItemL = "";
      for (x = nLen; x <= 7; x++)
      {
         szItemL = szItemL + System.Convert.ToString(0);
      }
      szItemL = szItemL + szItem.Substring(0, nLen - 4);
      ItemX.SubItems.Add(szItemL + ":" + szItemR);
      ItemX.SubItems.Add(LEADDICOM1.get_CurrentTag().Name);
      ItemX.SubItems.Add(System.Convert.ToString(LEADDICOM1.get_CurrentTag().VR));
      ItemX.SubItems.Add(System.Convert.ToString(LEADDICOM1.get_CurrentTag().MinVM));
      ItemX.SubItems.Add(System.Convert.ToString(LEADDICOM1.get_CurrentTag().MaxVM));
      ItemX.SubItems.Add(System.Convert.ToString(LEADDICOM1.get_CurrentTag().DivideVM));
      ItemX.Selected = true;
      ListView1.Refresh();
      ListView1.Focus();
      return;
   }
   catch
   {
      MessageBox.Show("Error");
   }
}