[英]How to display searched rows in messagebox
您能幫我在消息框中顯示搜索到的行嗎?
我在下面的代碼中搜索行中的值。
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("foo")
將在Windows窗體應用程序中顯示一個帶有foo
文本的消息框(我想這就是您的位置)。
您可以在此鏈接上了解有關該方法及其重載的更多信息。
以string
和愉快的編碼獲取所需的信息。
如果要執行的操作是在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.