【发布时间】:2016-05-12 22:47:39
【问题描述】:
我有一个显示 DataGridView 的简单表单;我想在同一个表单上的第一个下方显示第二个 DataGridView 对象。
但是当我运行代码时,它只显示第一个。通过调试器运行时,表单列出了它有两个数据网格视图链接到它。
System.Windows.Forms.Form form
= new System.Windows.Forms.Form();
form.Size = new System.Drawing.Size(450, 400);
form.Text = "Form";
DataGridView dg = new DataGridView();
dg.AllowUserToAddRows = false;
dg.AllowUserToDeleteRows = false;
dg.AllowUserToOrderColumns = true;
dg.Dock = System.Windows.Forms.DockStyle.Fill;
dg.Location = new System.Drawing.Point(0, 0);
dg.ReadOnly = true;
dg.TabIndex = 0;
dg.DataSource = dt;
dg.Parent = form;
DataGridView dgHangers = new DataGridView();
dgHangers.AllowUserToAddRows = false;
dgHangers.AllowUserToDeleteRows = false;
dgHangers.AllowUserToOrderColumns = true;
dgHangers.Dock = System.Windows.Forms.DockStyle.Fill;
// attempting get the bottom of the first DataGridView() so the second will display below.
dgHangers.Location = new System.Drawing.Point(0, dg.DisplayRectangle.Bottom);
dgHangers.ReadOnly = true;
dgHangers.TabIndex = 1;
dgHangers.DataSource = hangerTable;
dgHangers.Parent = form;
form.ShowDialog();
表格:
【问题讨论】: