public virtual void gridData_SelectionChanged(object sender, EventArgs e) { var value = 0M; var count = gridData.SelectedCells.Count; lblCount.Text = count.ToString(); foreach (dynamic item in gridData.SelectedCells) { try { value += (decimal)item.Value; } catch { lblSum.Text = ""; return; } } lblSum.Text = value.ToString(); if (gridData.SelectedCells.Count > 0) { DataGridViewCell[] cells = new DataGridViewCell[gridData.SelectedCells.Count]; gridData.SelectedCells.CopyTo(cells, 0); MultipleRowsSelected = cells.ToList().Select(x => x.RowIndex).Distinct().Count() > 1; } }