0

我这里有问题。我正在尝试显示 datagridview 列“值”中每个字符串出现的次数。我试图在每个值旁边显示每个事件(例如我想要这个:71->4、83->7、0B->6 等)。这是我的代码。结果我只接受第一个。提前致谢。

    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;
    }
4

1 回答 1

0

代替

if (searchTerm == null || searchTerm == String.Empty || searchTerm.Trim().Length == 0)

它应该是 :

if (r.Cells["Value_Detected"].Value != null)
于 2015-04-26T18:24:06.093 回答