顧客レコードを追加した後、DataGridViewのすべての顧客を表示し、DataGridViewの最初の行を選択する関数を呼び出します。DataGridViewセレクターが特定のレコードに移動する方法
現在、私の人口統計データグリッドビューは、今すぐ追加されています。今すぐ追加されたレコードがDataGridViewにあり、リストの最後にあり、DataGridViewから最初のレコードが選択されています。
private void btnAdd_Click(object sender, EventArgs e)
{
frmAddModifyCustomer addCustomerForm = new frmAddModifyCustomer();
addCustomerForm.addCustomer = true;
DialogResult result = addCustomerForm.ShowDialog();
if (result == DialogResult.OK)
{
customer = addCustomerForm.customer;
txtCustomerID.Text = customer.CustomerID.ToString();
this.DisplayCustomer();
this.AllCustomer();
}
}
private void AllCustomer()
{
DataTable dt = new DataTable();
try
{
dt = CustomerDB.AllCustomer();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.GetType().ToString());
}
if (dt != null)
{
grvCustomer.Visible = true;
grvCustomer.DataSource = dt;
}
else
{
MessageBox.Show("No customer found with this ID. " +
"Please try again.", "Customer Not Found");
grvCustomer.Visible = false;
this.ClearControls();
}
}
ありがとうございます。私はレコードを変更してリストの途中で、特定のr値(顧客ID)のecordは私にとってはより良いものでした。 – Masoud
この場合、行を列挙し、顧客IDダイアログの値と一致する行を見つける必要があります。私の答えの修正版を見てください。 –