示例#1
0
 /// <summary>
 /// Saves the settings of the ScannerView
 /// </summary>
 /// <param name="view">The ScannerView</param>
 public static void SaveScannerViewSettings(ScannerView view)
 {
     try
     {
         StringBuilder sbOut = new StringBuilder();
         string pipe = "";
         foreach (DataGridViewColumn col in view.scannerGrid.Columns)
         {
             //Add the column name and order
             sbOut.Append(pipe);
             sbOut.Append(col.Name);
             sbOut.Append(",");
             sbOut.Append(col.DisplayIndex);
             sbOut.Append(",");
             sbOut.Append(col.Visible);
             pipe = "|";
         }
         Settings.Default.gridOrder = sbOut.ToString();
     }
     catch (Exception)
     {
         //Something went wrong, ignore
     }
 }
示例#2
0
 /// <summary>
 /// Applies saved settings to the ScannerView
 /// </summary>
 /// <param name="view">The ScannerView</param>
 public static void ApplyScannerViewSettings(ScannerView view)
 {
     if(string.IsNullOrEmpty(Settings.Default.gridOrder)) return;
     try
     {
         //The string is like this:
         //<ColumnName>,<index>,<visible>|<ColumnName>,<index>,<visible>|<ColumnName>,<index>,<visible>|etc.
         string[] parts;
         foreach (string piece in Settings.Default.gridOrder.Split('|'))
         {
             parts = piece.Split(',');
             if (view != null)
             {
                 view.scannerGrid.Columns[parts[0]].DisplayIndex = Convert.ToInt32(parts[1]);
                 view.scannerGrid.Columns[parts[0]].Visible = parts[2] == "True";
             }
         }
     }
     catch (NullReferenceException)
     {
         //Something went wrong, ignore
     }
     catch (IndexOutOfRangeException)
     {
         //Something went wrong, ignore
     }
     catch (FormatException)
     {
         //Something went wrong, ignore
     }
     //refresh the context menu
     if (view != null) view.UpdateColumnList();
 }