c# - Form1 DataGridView 复制到 Form2 DataGridView
问题描述
我试图在datagridview中选择一行单击创建然后它将该行的特定单元格复制到form2(不制作新表单或覆盖现有数据),基本上就像采购订单一样。我可以用 2 个 Datagridviews 在同一个表单上做我需要做的事情
//THIS WORKS FOR DATAGRIDVIEWS ON SAME FORM//
if (this.dataGridView2.DataSource != null)
{
this.dataGridView2.DataSource = null;
}
else
{
// this.dataGridView2.Rows.Clear();
}
for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
{
int index = dataGridView2.Rows.Add();
dataGridView2.Rows[index].Cells[0].Value = dataGridView1.SelectedRows[i].Cells[5].Value.ToString();
dataGridView2.Rows[index].Cells[1].Value = dataGridView1.SelectedRows[i].Cells[2].Value.ToString();
dataGridView2.Rows[index].Cells[0].Value = dataGridView1.SelectedRows[i].Cells[5].Value.ToString();
dataGridView2.Rows[index].Cells[1].Value = dataGridView1.SelectedRows[i].Cells[2].Value.ToString();
但是当 Form2 上有相同的控件时将不起作用。我需要它以这种方式工作,但传输(复制)到 FrmMetalKit(Form2)
解决方案
推荐阅读
- java - Hibernate:外部连接配置文件
- indexing - 如果另一个表上的值包含在单元格中,则 TEXTJOIN 的 INDEX MATCH 唯一值
- laravel - 单独的自定义和供应商资产 laravel 结构
- android - Android数据绑定找不到接受参数类型*的*的setter
- css - 将 padding-right 添加到
- python - 如何将 ipynb 源文件用作笔记本?
- python-3.x - 我正在为 AutoKey 密码编写代码,但出现“str 对象不支持项目分配”的错误。有没有更好的编码方法?
- image - 带有颤振的 DOCUMENT_TEXT_DETECTION(网络)
- javascript - 状态更新事件垃圾邮件
- javascript - 创建一个重复传递的组件 onClick 或 onSubmit 的组件