سلام، یه همچین چیزی میشه
using System;
using System.Windows.Forms;
namespace DGV
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.dataGridView1.Rows.Add(1, "سیاوش", "ابراهیمی");
this.dataGridView1.Rows.Add(2, "سروش", "ابراهیمی");
this.dataGridView1.Rows.Add(3, "سارا", "امرایی");
this.dataGridView1.Rows.Add(4, "محسن", "نظری");
this.dataGridView1.Rows.Add(5, "ادیب", "سوری");
}
private void txtID_TextChanged(object sender, EventArgs e)
{
bool isFound = false;
for (int i = 0; i < this.dataGridView1.RowCount; i++)
{
string id = this.dataGridView1.Rows[i].Cells["Id"].Value.ToString();
if (id == this.txtID.Text)
{
this.txtFirstName.Text = this.dataGridView1.Rows[i].Cells["FirstName"].Value.ToString();
this.txtLastName.Text = this.dataGridView1.Rows[i].Cells["LastName"].Value.ToString();
isFound = true;
break;
}
}
if (!isFound)
{
this.txtFirstName.Text = string.Empty;
this.txtLastName.Text = string.Empty;
}
}
}
}