在过滤datagridview中的数据后,如何在文本框中显示第一个选定的行值?
private void btnsearch_Click(object sender, EventArgs e)
{
dgpay.DataSource = p.SearchInPaymentVouchers("PaymentVouchers.VendorID", comven.SelectedValue.ToString());
}
答案 0 :(得分:1)
private void btnsearch_Click(object sender, EventArgs e)
{
DataTable dt = p.SearchInPaymentVouchers("PaymentVouchers.VendorID", comven.SelectedValue.ToString());
dgpay.DataSource = dt;
//Code to bind first row in textbox.
//check if the datatable has rows
if(dt.Rows.Count > 0)
{
textbox.text = Convert.ToInt32(dt.Rows[0]["id"]);
//Row[line index you want to get]["Header of datatable column ex VendorID"]
}
}
希望这是你真正想要的。如果您遇到任何问题,请随时询问。