Connecting Tech Pros Worldwide Forums | Help | Site Map

How do I: Find the total of unique values in a datagrid column?

Lokean's Avatar
Member
 
Join Date: Apr 2007
Posts: 71
#1: Jun 7 '07
I have a datagrid that is populated by the results of a function which is fed parameters from my program.

I'm searching for machines reporting on a certain status.

What I need to do is calculate the % of machines with that status.

I have the total number of machines in another query, so I am good there.

What I need to do now is get a count of distinct machines from my result set in the datagrid. (A second hit against the database is prohibeted by business rules)

any ideas?

nateraaaa's Avatar
Expert
 
Join Date: May 2007
Location: Illinois
Posts: 663
#2: Jun 7 '07

re: How do I: Find the total of unique values in a datagrid column?


You could loop through your datagrid and get the cell text for each row that contains the machine name. Add the text for each cell column containing the machine name to an ArrayList. You could then remove duplicates from the ArrayList so that you have a total of unique values in that column. Then divide the number of unique machine names by the total number of machines to get the percentage you are trying to find.

See this site for an example of using the ArrayList to get unique values.

http://authors.aspalliance.com/olson/methods/RemoveDups.aspx

Good Luck

Nathan
Lokean's Avatar
Member
 
Join Date: Apr 2007
Posts: 71
#3: Jun 7 '07

re: How do I: Find the total of unique values in a datagrid column?


Quote:

Originally Posted by nateraaaa

You could loop through your datagrid and get the cell text for each row that contains the machine name. Add the text for each cell column containing the machine name to an ArrayList. You could then remove duplicates from the ArrayList so that you have a total of unique values in that column. Then divide the number of unique machine names by the total number of machines to get the percentage you are trying to find.

See this site for an example of using the ArrayList to get unique values.

http://authors.aspalliance.com/olson/methods/RemoveDups.aspx

Good Luck

Nathan


Thanks Nathan, I appreciate the help!
Reply