我已经详尽地研究过(搜索到)这个问题的解决方案,但找不到任何答案。我的问题是,在Form1中选择一行(为了清晰起见),它不会将值传递给Form2中的DataGridView
。请注意,所有列标题都会被传送。将选定的DataGridView行转换为另一种形式的新DataGridView
这里是Form1中的一个片段:
private void customersDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
OrderSearchForm orderform = new OrderSearchForm();
orderform.Row = this.customersDataGridView.CurrentRow;
orderform.MdiParent = this.MdiParent;
orderform.Show();
}
1和Form 2:
private DataGridViewRow row;
public DataGridViewRow Row
{
get { return row; }
set { row = value; }
}
private void OrderSearchForm_Load(object sender, EventArgs e)
{
NorthwindDataClassesDataContext db = new NorthwindDataClassesDataContext();
DataGridViewRow r = row.Clone() as DataGridViewRow;
foreach (DataGridViewCell cell in row.Cells)
{
this.OrderSearchgridview.Columns.Add(cell.OwningColumn.Name,
cell.OwningColumn.HeaderText);
r.Cells[cell.ColumnIndex].Value = cell.Value;
}
OrderSearchgridview.Rows.Add(r);
}
所以基本上,我的问题是,我该如何显示从Form1的DataGridView
在窗体2的DataGridView
行值?
我觉得我错过了插入列后添加实际值的一个步骤,但我坚持了这一点。
你在Form1中绑定到DataGridView的哪些数据? –