c# - Find occurrences of each value of a datagridview column in a text and display each occurrence to the next column -
i having problem here. trying display how many times each 1 of strings in datagridview column "values" appear. trying display each occurrence next each value(for example want this: 71->4, 83 ->7 , 0b->6 etc.). here code. i'm taking result first one. 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 = wor in words wor.toupperinvariant() == searchterm.toupperinvariant() select wor; int wordcount = matchquery.count(); r.cells["occur"].value = wordcount.tostring(); } } button4.enabled = false; }
instead of
if (searchterm == null || searchterm == string.empty || searchterm.trim().length == 0)
it should :
if (r.cells["value_detected"].value != null)
Comments
Post a Comment