private void CreateTotalsControl() { foreach (DataGridViewColumn dgvColumn in DisplayedColumns) { var totalcolumn = metroGrid.TotalColumns.Find(p => { return(p.ColumnName == dgvColumn.Name); }); if (totalcolumn != null) { var ml = new MetroGridTotalControl { Top = 2, Height = metroGrid.RowTemplate.Height, UseStyleColors = totalcolumn.UseStyleColor, Visible = dgvColumn.Visible, Text = totalcolumn.Text, FontSize = totalcolumn.FontSize, FontWeight = totalcolumn.FontWeight, TextAlign = totalcolumn.TextAlign, MaxWholeDigits = totalcolumn.MaxWholeDigits, MaxDecimalPlaces = totalcolumn.MaxDecimalPlaces, AllowNegative = totalcolumn.AllowNegative, ShowPrefix = totalcolumn.ShowPrefix, AllowGroupSeparator = totalcolumn.AllowGroupSeparator, CurrencySimbol = totalcolumn.CurrencySimbol }; Controls.Add(ml); totalcolumn.Column = dgvColumn; totalcolumn.Control = ml; } } }
private void CalculateCount(string columnName, MetroGridTotalControl control) { if (control != null) { control.Int = metroGrid.RowCount; } }
private void CalculateSum(string columnName, MetroGridTotalControl control) { var total = 0.0; foreach (DataGridViewRow dgw in metroGrid.Rows) { if (!dgw.IsNewRow) { total += dgw.GetValue <double>(columnName); } } if (control != null) { control.Double = total; } }
private void CalculateMax(MetroGridColumnType totalColumnType, string columnName, MetroGridTotalControl control) { var maxInt = int.MinValue; var maxDouble = double.MinValue; var maxDate = DateTime.MinValue; var maxString = string.Empty; switch (totalColumnType) { case MetroGridColumnType.Double: foreach (DataGridViewRow dgw in metroGrid.Rows) { if (!dgw.IsNewRow && dgw.GetValue <double>(columnName) > maxDouble) { maxDouble = dgw.GetValue <double>(columnName); } } if (control != null) { control.Double = maxDouble; } break; case MetroGridColumnType.Int: foreach (DataGridViewRow dgw in metroGrid.Rows) { if (!dgw.IsNewRow && dgw.GetValue <int>(columnName) > maxInt) { maxDouble = dgw.GetValue <int>(columnName); } } if (control != null) { control.Int = maxInt; } break; case MetroGridColumnType.Date: foreach (DataGridViewRow dgw in metroGrid.Rows) { if (!dgw.IsNewRow && dgw.GetValue <DateTime>(columnName) > maxDate) { maxDouble = dgw.GetValue <int>(columnName); } } if (control != null) { control.DateTime = maxDate; } break; } }