I am having a problem here. I am trying to display how many times each one of the strings in datagridview column "Values" appear. I am trying to display each occurrence next to each value(for example I want this: 71->4, 83 ->7 , 0B->6 etc.). Here is my code. I'm only taking as a result the first one. Thanks in advance.
private void button4_Click(object sender, EventArgs e)
{
string Text = richTextBox1.Text;
string[] words = Text.Split(' ');
foreach (string word in words)
{
dataGridView1.Rows.Add(word);
}
string searchTerm = " " ;
foreach (DataGridViewRow r in dataGridView1.Rows )
{
if (searchTerm == null || searchTerm == String.Empty || searchTerm.Trim().Length == 0)
{
searchTerm = r.Cells["Value_Detected"].Value.ToString();
var matchQuery = from wor in words
where wor.ToUpperInvariant() == searchTerm.ToUpperInvariant()
select wor;
int wordCount = matchQuery.Count();
r.Cells["Occur"].Value = wordCount.ToString();
}
}
button4.Enabled = false;
}