/// <summary> /// Initializes a new instance of the <see cref="LocalSwitch"/> class. /// from a row in the setupDialog dataGridView. /// Depends on the column names being correct. /// </summary> /// <param name="cells">A row of cells from the setupDialog</param> internal LocalSwitch(System.Windows.Forms.DataGridViewCellCollection cells) { this.Name = (string)cells["switchName"].Value; this.Minimum = Convert.ToDouble(cells["colMin"].Value); this.Maximum = Convert.ToDouble(cells["colMax"].Value); this.StepSize = Convert.ToDouble(cells["colStep"].Value); this.Value = Convert.ToDouble(cells["colValue"].Value); this.CanWrite = Convert.ToBoolean(cells["colCanWrite"].Value); if (cells["colDescription"].Value is string) { this.Description = (string)cells["colDescription"].Value; } }
/// <summary> /// Convert form String arr from colums to CSV line /// </summary> /// <param name="s">List of string from colums</param> /// <param name="c">Separator between columns</param> /// <returns></returns> public static string ConvertListstrtoCSVline(System.Windows.Forms.DataGridViewCellCollection s, char c = ',', bool always = false) { bool isquote = false; string sn = "", sr = ""; for (int j = 0; j < s.Count; j++) { if (s[j].Value == null) { isquote = true; } for (int i = 0; s[j].Value != null && i < ((string)(s[j].Value)).Length; i++) { if (((string)(s[j].Value))[i] == '"') { sn += '"'; sn += ((string)(s[j].Value))[i]; isquote = true; continue; } if (isquote) { sn += ((string)(s[j].Value))[i]; continue; } if (((string)(s[j].Value))[i] == c) { sn += ((string)(s[j].Value))[i]; isquote = true; continue; } if (!isquote) { sn += ((string)(s[j].Value))[i]; continue; } } if (isquote || always) { sn = '"' + sn + '"'; } sr += sn; sr += c; sn = ""; isquote = false; } sr = sr.Substring(0, Math.Max(0, sr.Length - 1)); return(sr);//.TrimEnd(c); }
/// <summary> /// Determines whether the specified row of cells contains a valid LocalSwitch definition. /// </summary> /// <param name="cells">The cells.</param> /// <param name="reason">The reason.</param> /// <returns> /// <c>true</c> if the specified cells is valid; otherwise, <c>false</c>. /// </returns> internal static bool IsValid(System.Windows.Forms.DataGridViewCellCollection cells, out string reason) { var name = (string)cells["switchName"].Value; var minimum = Convert.ToDouble(cells["colMin"].Value); var maximum = Convert.ToDouble(cells["colMax"].Value); var stepSize = Convert.ToDouble(cells["colStep"].Value); var value = Convert.ToDouble(cells["colValue"].Value); if (!IsValid(name, maximum, minimum, stepSize, value, out reason)) { return(false); } reason = string.Empty; return(true); }
public static IEnumerable <System.Windows.Forms.DataGridViewCell> AsEnumerable(this System.Windows.Forms.DataGridViewCellCollection source) { TypeCheckEnumerable(source, (s) => s.AsEnumerable(), (s) => s[0]); return(source.Cast <System.Windows.Forms.DataGridViewCell>()); }
public static IList <System.Windows.Forms.DataGridViewCell> AsIList(this System.Windows.Forms.DataGridViewCellCollection source) { return(IListWrapper.Get(source, s => s[0])); }