Click here to Skip to main content
15,917,645 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to count distinct value from the dataGrid view, but this error triggers

What I have tried:

int countDiffHallId = dgvEachHallOrGarden.Rows
                           .Cast<DataGridViewRow>()
                           .Select(r => (int)r.Cells["clientId"].Value)
                           .Distinct()
                           .Count();
Posted
Updated 20-Sep-21 22:55pm

The clientId cell in one of your rows does not contain an int value.

We can't tell you which, since we don't have access to your view nor your data.

You will need to debug your code to see what type the values actually are.
 
Share this answer
 
Break it down into separate "chunks" - at a guess at least one of your clientID Cells does not contain a numeric value and it's the (int) cast that is failing.
We can't check that - we have no access to your data!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900