简体   繁体   English

如何在消息框中显示搜索到的行

[英]How to display searched rows in messagebox

can you please help me on displaying the searched row in message box? 您能帮我在消息框中显示搜索到的行吗?

I've below code for searching a value in the row. 我在下面的代码中搜索行中的值。

private void button3_Click(object sender, EventArgs e)
{
        // Code to search the  alphanumneric Part Number (in Column1 header called "Name") and highlihgt the row

    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
        if (row.Cells["Age"].Value.ToString().Equals(textBox3.Text.StringComparison.CurrentCultureIgnoreCase))   
        {  
            dataGridView1.Rows[row.Index].Selected = true;
        }
    }
}

The following: 下列:

MessageBox.Show("foo")

Will display a message box with the text foo in a Windows form application (which I suppose is what you have there). 将在Windows窗体应用程序中显示一个带有foo文本的消息框(我想这就是您的位置)。

You can learn more about the method and its overloads on this link . 您可以在此链接上了解有关该方法及其重载的更多信息。

Get the information you want in a string and happy coding. string和愉快的编码获取所需的信息。

If what you are trying to do is display the Name column's value in a MessageBox then do the following: 如果要执行的操作是在MessageBox显示“ Name列的值,请执行以下操作:

private void button3_Click(object sender, EventArgs e)
{
    // Code to search the  alphanumneric Part Number (in Column1 header called "Name") and highlihgt the row

    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
        if (row.Cells["Age"].Value.ToString().Equals(textBox3.Text.StringComparison.CurrentCultureIgnoreCase))   
        {  
            dataGridView1.Rows[row.Index].Selected = true;
            MessageBox.Show(row.Cells["name"].Value.ToString());
            break;  //This exits the `foreach` loop - not necessary just an assumption.
        }
        else
        {
            //Do something if you don't find what you wanted or `continue` if you want the loop to keep going.
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM