Only if you have a list that you're updating that you bind to the datagridview, otherwise you're using Linq for the data from the first list to get the count. Dictionary's do not bind directly either.
Code
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public enum Gender { Male, Female }
public class Person
{
public string Name { get; set; }
public Gender Gender { get; set; }
}
public class PersonList : List<Person>, IListSource
{
public bool ContainsListCollection => true;
public IList GetList() => this;
public IList GetCountList() =>
(from p in this
group p by p.Name into g
select new { Name = g.Key, Count = g.Count() }).ToList();
}
public partial class Form1 : Form
{
public Form1() => InitializeComponent();
private readonly PersonList _people = new PersonList();
private void Form1_Load(object sender, EventArgs e)
{
_people.Add(new Person() { Name = "Bob", Gender = Gender.Male });
_people.Add(new Person() { Name = "Taylor", Gender = Gender.Male });
_people.Add(new Person() { Name = "Taylor", Gender = Gender.Female });
dataGridView1.DataSource = _people;
dataGridView2.DataSource = _people.GetCountList();
}
}
}
Then depending on whether you're allowing the datagridview to be edited expecting 2-way binding, things get a little more tricky. You may want to implement IRaiseItemChangedEvents, IBindingList as well, in which case it might be better to implement IList as well instead of inheriting from List<Person> to broadcast changes to the list for each.