效果展示:
代码逻辑:首先在datagridview1中按条件查询数据,然后在datagridview2在查询和datagridview1中一样的Select语句,只不过在datagridview2的查询语句中需添加where条件获取datagridview1在选中行的id,在datagridview2显示就好了
代码:单据筛选按钮
private void button1_Click(object sender, EventArgs e)
{
string wldm = txtId.Text.Trim();
string wlmc = txtName.Text.Trim();
string wlgg = txtGg.Text.Trim();
string str = "select id, materialsId as 物料代码, materialsName as 物料名称, specification as 规格型号,auxiliarysign as 助记号,stockId as 仓库代码,stockName as 仓库名称 ,unitNumber as 数量,unit as 单位,kuwei as 库位,weight as 重量数量,weightUnit as 重量单位,remark as 备注,purchasingPrice as 最新进价 ,stockAmount as 库存金额 from MaterialStock where materialsId like '%"+wldm+ "%' and materialsName like '%" + wlmc + "%' and specification like '%" + wlgg + "%'";
da = new SqlDataAdapter(str, SQL);
dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.Columns["id"].Visible = false;
}
2、单据datagridview找到事件CellDoubleClick,双击他,今入代码编辑界面,代码如下:
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
string id = dataGridView1.Rows[e.RowIndex].Cells["id"].Value.ToString();
string str = "select id, materialsId as 物料代码, materialsName as 物料名称, specification as 规格型号,auxiliarysign as 助记号,stockId as 仓库代码,stockName as 仓库名称 ,unitNumber as 数量,unit as 单位,kuwei as 库位,weight as 重量数量,weightUnit as 重量单位,remark as 备注,purchasingPrice as 最新进价 ,stockAmount as 库存金额 from MaterialStock where id = '"+id+"'";
da = new SqlDataAdapter(str, SQL);
dt = new DataTable();
da.Fill(dt);
dataGridView2.DataSource = dt;
dataGridView2.Columns["id"].Visible = false;
}
这样子就完成了
标签:string,c#,代码,id,选中,datagridview1,datagridview2,dt,双击 From: https://www.cnblogs.com/45fdsf4s4sdfsddv/p/17570438.html