我有一个填充 DGV 的查询,看起来像
private void textBox6_Leave(object sender, EventArgs e)
{
DataClasses3DataContext db = new DataClasses3DataContext();
int matchedAdd = (from c in db.GetTable<prop>()
where c.HOUSE_NO.Contains(textBox1.Text) && c.Direction.Contains(textBox2.Text) && c.street.Contains(textBox3.Text) && c.SUFF.Contains(textBox4.Text)
select c.ID).SingleOrDefault();
var before = (from c in db.GetTable<prop>()
where c.ID < matchedAdd
orderby c.PARCEL descending
select c).Take(6);
var after = (from c in db.GetTable<prop>()
where c.ID > matchedAdd
orderby c.PARCEL
select c).Take(6);
var endResult = before.Concat(after);
dgvBRT.DataSource = endResult;
}
在由该查询填充后,我需要能够从 DGV 中选择一行并打开 BRTDetail。这是我第一次不得不使用未绑定的网格。我通常使用的代码如下。显然它不起作用,因为此时 BRTDataSet 无关紧要。在这种情况下如何选择一行?
private void dgvBRT_DoubleClick(object sender, EventArgs e)
{
System.Data.DataRowView SelectedRowView;
BRTDataSet.propRow SelectedRow;
SelectedRowView = (System.Data.DataRowView)propBindingSource.Current;
SelectedRow = (BRTDataSet.propRow)SelectedRowView.Row;
frmBRTDetail BRTDetail = new frmBRTDetail(this);
BRTDetail.LoadBRTNumberKey(SelectedRow.PARCEL, null);
BRTDetail.LoadBldgKey(SelectedRow.BLDG_CD, null);
BRTDetail.Show();
}