public static void DoConversion(DataGridView dataGridView1, StatHelperClass shc, string Text, int colIndex) { if (shc.DoConversion(Text)) { for (int i = 2; i < 6; i++) { double value = double.NaN; switch (i) { case StatHelperClass.SumIndex: value = shc.sum; break; case StatHelperClass.MinIndex: value = shc.min; break; case StatHelperClass.MaxIndex: value = shc.max; break; case StatHelperClass.MeanIndex: value = shc.mean; break; } dataGridView1[colIndex, i].Value = value.ToString("N"); } dataGridView1[colIndex, 0].Value = Text; } }
public static int EnsureColumnsInDataGrid(StatHelperClass shc, DataGridView dataGridView1) { if (dataGridView1.Columns.Count == 0) { dataGridView1.Columns.Add("nm", "Statistic"); dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable; } string col = shc.GetColumnHeadings(); if (dataGridView1.Columns.Contains(col)) { return dataGridView1.Columns[col].Index; } DataGridViewColumn dvc = new DataGridViewColumn(); dvc.Name = col; dvc.HeaderText = col; dvc.SortMode = DataGridViewColumnSortMode.NotSortable; dvc.CellTemplate = new DataGridViewTextBoxCell(); dvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; return dataGridView1.Columns.Add(dvc); }