datagridview 双击cell弹出两个窗体为什么?

fengdao341 fengdao341 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public partial class Form2 : Form
{
private DataGridView masterDataGridView = new DataGridView();
private BindingSource masterBindingSource = new BindingSource();
private DataGridView detailsDataGridView = new DataGridView();
private BindingSource detailsBindingSource = new BindingSource();

public Form2()
{
masterDataGridView.Dock = DockStyle.Fill;
detailsDataGridView.Dock = DockStyle.Fill;

SplitContainer splitContainer1 = new SplitContainer();
splitContainer1.Dock = DockStyle.Fill;
splitContainer1.Orientation = Orientation.Horizontal;

splitContainer1.Panel1.Controls.Add(masterDataGridView);
splitContainer1.Panel2.Controls.Add(detailsDataGridView);

this.Controls.Add(splitContainer1);
this.Load += new System.EventHandler(Form2_Load);
this.Text = "DataGridView master/detail demo";

InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)
{
masterDataGridView.DataSource = masterBindingSource;
detailsDataGridView.DataSource = detailsBindingSource;
GetData();
masterDataGridView.AutoResizeColumns();
masterDataGridView.CellMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(masterDataGridView_CellMouseDoubleClick);

detailsDataGridView.AutoSizeColumnsMode =DataGridViewAutoSizeColumnsMode.AllCells;

}
string bianma = "";

private void masterDataGridView_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
bianma = masterDataGridView.Rows[e.RowIndex].Cells[3].Value.ToString();

EditType o = new EditType(bianma);
o.Show();
}

private void GetData()
{
try
{

String connectionString = "Data Source=localhost;Initial Catalog=wisvenue;Persist Security Info=True;User ID=sa;Password=cyber";

SqlConnection connection = new SqlConnection(connectionString);
DataSet data = new DataSet();
data.Locale = System.Globalization.CultureInfo.InvariantCulture;
SqlDataAdapter masterDataAdapter = new
SqlDataAdapter("select * from typename", connection);
masterDataAdapter.Fill(data, "typename");
SqlDataAdapter detailsDataAdapter = new
SqlDataAdapter("select * from cardtime", connection);
detailsDataAdapter.Fill(data, "cardtime");
DataRelation relation = new DataRelation("CustomersOrders",
data.Tables["typename"].Columns["种类编码"],
data.Tables["cardtime"].Columns["种类编码"]);
data.Relations.Add(relation);
masterBindingSource.DataSource = data;
masterBindingSource.DataMember = "typename";
detailsBindingSource.DataMember = "CustomersOrders";
}
catch (SqlException)
{
MessageBox.Show("To run this example, replace the value of the " +
"connectionString variable with a connection string that is " +
"valid for your system.");
}

}
}
...全文

相关推荐

DataGridView中同一个Cell中显示图片和文字

在DataGridView中,通过CellPainting事件来重新绘制单元格,来实现同一个单元格中显示图片和文字。

Kim_Du

C#+SQL Server火车信息管理系统源码解析:从建表到避坑

在桌面数据库应用开发中,基于C#与SQL Server的WinForms项目一直是课程设计和企业工具的热门选择。理解其核心流程,包括SqlConnection连接管理、SqlDataAdapter数据填充、DataSet与DataGridView绑定,就能快速搭建出可用的管理系统。这类系统通常涉及用户权限分流、多条件模糊查询、数据表关联及配置文件连接字符串的修改等关键环节。本文以一套完整的火车信息管理系统源码为例,从数据库表设计、窗体职责划分到登录验证、车次查询、列映射,再到常见连接失败、中文乱码、编译环境

weixin_33801856

基于C#的WinForms学生信息管理系统:从选型到避坑全解析

在桌面应用开发中,数据存储方案与界面框架的选型直接影响项目的交付稳定性。C#搭配WinForms是构建表单密集型管理系统的高效路径,而SQLite、Access与SQL Server等数据库则需根据并发能力和部署环境灵活取舍。掌握连接字符串、参数化查询与三层架构等基础原理,能显著规避运行时依赖和数据安全风险。以学生信息管理这类典型业务场景为切入点,文章系统梳理了从建表、数据访问层到登录权限、导入导出的完整实现流程,并针对路径写死、32/64位兼容、Excel中文乱码等高频故障给出了可落地的排查与解决手段,为

菩提风

C#图书管理系统实操指南:SQL Server数据库附加与三层架构落地

C# WinForm应用程序是Windows桌面开发的基础技术路径,其核心在于WinForm界面、ADO.NET数据访问与SQL Server本地数据库的协同工作。理解连接字符串配置、数据库附加流程及BLL/DAL/Model分层原理,是掌握C#桌面应用开发的关键门槛。本文围绕一个真实可运行的三层架构图书管理系统,详解SQL Server数据库(.mdf/.ldf)如何正确附加、app.config连接字符串如何适配不同实例名、以及DAL层SqlHelper封装与BLL层职责边界等工程实践要点,覆盖从环境搭

weixin_34323858

npoi读取excel并用datagridview显示出来

用npoi读取excel文件,并且显示到datagridview中,按行显示。

予非池物
评论 2
收藏 已收藏
分享
返回顶部
fengdao341
C# 111,130 成员 642,540 内容