title: How to achieve Count(Distinct {x}) from dataTable using c#?
body: <p>I want to find out the count of the distinct values of a particular column of a DataTable and store the result in listbox.</p>
  
  <hr>
  
  <p>Currently, I have the code to extract the distinct values of a column of a DataTable and store it in a ListBox as follows:-</p>
  
  <pre><code> var ids = dt.AsEnumerable()
                      .Select(s =&gt; new
                      {
                          EventID = s.Field&lt;Int32&gt;("ID"),
                      })
                      .Distinct().ToList();
  
                 listBox.DataSource = ids;
  </code></pre>
  
  <p>where dt is the name of the DataTable</p>
  
  <h2>ID is the name of the column</h2>
  
  <p>For Eg:-</p>
  
  <p>Table is</p>
  
  <pre><code> Name   ID    Marks
   Ashish 10     200
   Ram    100    300
   Sur    200    800
   Shim   10     899
   Kam    100    989
  </code></pre>
  
  <p>Then the result in the listbox should appear as:-</p>
  
  <pre><code>{ID=10}{Count=2}
  {ID=100}{Count=2}
  {ID=200}{Count=1}
  </code></pre>
  
  <p>Currently I am getting output as:-</p>
  
  <pre><code>{ID=10}
  {ID=100}
  {ID=200}
  </code></pre>
  
  <p>Please help!!</p>