首页 > 编程语言 >c#、winfrom在一个窗体中鼠标双击datagridview1选中某行,将其选中的行的所有数据在datagridview2中显示

c#、winfrom在一个窗体中鼠标双击datagridview1选中某行,将其选中的行的所有数据在datagridview2中显示

时间:2023-07-21 10:12:43浏览次数:38  
标签:string c# 代码 id 选中 datagridview1 datagridview2 dt 双击

效果展示:

代码逻辑:首先在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

相关文章

  • clion申请教育认证
    clion申请教育认证1、注册jetbrains账号jetbrains注册账号网站链接邮箱没有限制,qq邮箱即可,注册时候会给qq邮箱发送邮件,前往qq邮箱进行确认即可,如下图。2、教育认证点击注册完页面的Applyforafreestudentorteacherlicense选项或者跳转教育认证https://www.jetbrain......
  • Navicat连不上mysql8
    今天使用navicat连接mysql8,发现错误连连错误1:1130-Host'192.168.50.2'isnotallowedtoconnecttothisMySQLserver  错误2:2059-Authenticationplugin'caching_sha2_password'cannotbeloaded:Thespecifiedmodulecouldnotbefound  登录mysql,并切......
  • go 结构体嵌套interface
    packagemainimport"fmt"//结构体嵌套接口,可以在结构体绑定的方法直接实现接口中的方法,直接调用接口中的方法typeaainterface{ a() b()}typeworldstruct{ aa Ageint}func(hworld)a(){ fmt.Println("helloa方法")}func(hworld)b(){ fmt.Println("hello......
  • 查看 docker 服务
    查看Docker服务Docker是一个开源的容器化平台,可以帮助开发者快速构建、部署和运行应用程序。在使用Docker之前,我们需要先了解如何查看Docker服务的状态,确保它已正确安装并正在运行。1.检查Docker是否已安装首先,我们需要检查Docker是否已经安装在我们的机器上。在Li......
  • 触摸屏与PLC之间无线Ethernet通信
    在实际系统中,同一个车间里分布多台PLC,由触摸屏集中控制。通常所有设备距离在几十米到上百米不等。在有通讯需求的时候,如果布线的话,工程量较大且不美观,这种情况下比较适合采用无线通信方式。本方案以威纶通触摸屏和2台西门子S7-200SMART为例,介绍触摸屏与多台PLC的无线Ethernet通信......
  • 小白也能看懂的 ROC 曲线详解
    作者:PrimiHub-KevinROC曲线是一种坐标图式的分析工具,是由二战中的电子和雷达工程师发明的,发明之初是用来侦测敌军飞机、船舰,后来被应用于医学、生物学、犯罪心理学。如今,ROC曲线已经被广泛应用于机器学习领域的模型评估,说到这里就不得不提到TomFawcett大佬,他一直在致力于......
  • css旋转木马代码示例
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>Title</title><style>/*透视*/body{perspective:1000px;}.box{......
  • centos7升级PHP7
    centos7升级PHP7.2到8.0参考:https://blog.csdn.net/hy6533/article/details/120323038宿主机部署5.0https://blog.csdn.net/litaimin/article/details/1146365271.删除老版本yumlistinstalled|grepphpyumremovephp*上面输出内容2.安装PEPL软件源sudoyum-yinst......
  • nproc
    nproc打印可用的处理器单元数量。概要nproc[OPTION]...主要用途打印可用的处理器单元数量。选项--all打印已安装处理器的数量。--ignore=N如果可以的情况下,排除N个处理单元。--help显示帮助信息并退出。--version显示版本信息并退出。......
  • nacos适配达梦、瀚高、人大金仓数据库及部分源码探究
    一.插件实现1.插件目录结构2.pom依赖<dependency><groupId>com.alibaba.nacos</groupId><artifactId>nacos-datasource-plugin</artifactId><version>2.2.4</version></d......