Hi all,

I am currently trying to figure out how to take column results from a datagridview and group them so I can see how many of each are in the column. I want to take this data and use it to populate a combo box.

Example:

If the column contained:

Orange
Orange

Apple
Apple
Apple

Then the output would be:

Orange = 2
Apple = 3
NULL = 1

The BIG problem I have is that I will have no idea what the contents will be. Orange could be 25W, A, B, or C (essentially anything). So I'm thinking I will have to end up using an array with some conditions but I do not know exactly how to go about it.

Hopefully someone can point me in a direction. I am using vb.NET 2008. I am new to the site and have searched, but have not been able to catch anything similar. Thanks in advance.

Well, one way you could go about it, is using the Dictionary class (in System.Collections.Generic). Set the key to string and the value to integer (Dictionary<string, int>). Then for each column, first check if the Dictionary contains the key, add one to its value, if not create a key and initialize it to 1.