Exemplo n.º 1
0
 /// <summary>
 /// Insert a new data after a given position
 /// </summary>
 /// <param name="list">data list</param>
 /// <param name="po">printer object</param>
 /// <returns>added variable</returns>
 public static bool InsertAfter(ListBox list, PrinterObject po)
 {
     if (list.SelectedIndices.Count == 1)
     {
         int  pos = list.SelectedIndices[0];
         Data d   = new Data();
         FillVars(d.Controls["vars"] as ListBox, po);
         DialogResult dr = d.ShowDialog();
         if (dr == DialogResult.OK)
         {
             bool byVar = (d.Controls["rbVariable"] as RadioButton).Checked;
             if (byVar)
             {
                 po.InsertUseVariableAfter(pos, d.Controls["vars"].Text);
             }
             else
             {
                 po.InsertDataAfter(pos, d.Controls["txtConst"].Text);
             }
             if (pos + 1 < list.Items.Count)
             {
                 list.Items.Insert(pos + 1, po.Datas.ElementAt(pos + 1));
             }
             else
             {
                 list.Items.Add(po.Datas.ElementAt(pos + 1));
             }
             list.Refresh();
             hasModified = true;
             return(true);
         }
     }
     return(false);
 }