c#实现两个datagridview数据行移动
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
public string str_sql1 = "select * from Cargo order by logisticNum desc";
public string str_sql2 = "select * from Cargo where 1=2";//获取空表结构
private void DispatchCar_Load(object sender, EventArgs e)
{
dbclass.InSetDataGrideView(str_sql1, dataGridView1, "Cargo");
dbclass.InSetDataGrideView(str_sql2, dataGridView2, "Cargo");
}
private void DGVMove(DataGridView dgv1, DataGridView dgv2)
{
if(dgv1.SelectedRows.Count > 0)
{
DataGridViewRow newRow = dgv1.SelectedRows[0];
DataRowView drv = (DataRowView)newRow.DataBoundItem;
((DataTable)dgv2.DataSource).Rows.Add(drv.Row.ItemArray);//添加
dgv1.Rows.Remove(newRow);//删除
}
}
private void btnAllIN_Click(object sender, EventArgs e)
{
if (dataGridView1.Rows.Count > 0)
{
for(int i = 0;i
DataGridViewRow newRow = dataGridView1.Rows[i];
DataRowView drv = (DataRowView)newRow.DataBoundItem;
((DataTable)dataGridView2.DataSource).Rows.Add(drv.Row.ItemArray);//添加
}
dbclass.InSetDataGrideView(str_sql2, dataGridView1, "Cargo");
}
}
private void btnOneIn_Click(object sender, EventArgs e)
{
if (dataGridView1.Rows.Count > 0)
{
DGVMove(dataGridView1, dataGridView2);
}
}
private void btnAllOut_Click(object sender, EventArgs e)
{
if (dataGridView2.Rows.Count > 0)
{
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
DataGridViewRow newRow = dataGridView2.Rows[i];
DataRowView drv = (DataRowView)newRow.DataBoundItem;
((DataTable)dataGridView1.DataSource).Rows.Add(drv.Row.ItemArray);//添加
}
dbclass.InSetDataGrideView(str_sql2, dataGridView2, "Cargo");
}
}
private void btnOneOut_Click(object sender, EventArgs e)
{
if (dataGridView2.Rows.Count > 0)
{
DGVMove(dataGridView2, dataGridView1);
}
}
private void btnSearch_Click(object sender, EventArgs e)
{
string sql = "select * from Cargo where logisticNum like '%" + this.txtSearchLogisticsNum.Text + "%' and cargoName like '%" + this.txtSearchCargoName.Text + "%' and station like '%" + this.txtSearchStation.Text + "%' and drawin like '%" + this.txtSearchDrawin.Text + "%' order by logisticNum desc";
dbclass.InSetDataGrideView(sql, dataGridView1, "Cargo");
}