基本上,我有以下代码可以根据单击的按钮显示 3 个不同的数据网格视图。
public partial class ChooseDB : Form
{
private DataGridView doctorsDataGridView = new DataGridView();
private DataGridView patientsDataGridView = new DataGridView();
private DataGridView hospitalsDataGridView = new DataGridView();
public ChooseDB()
{
InitializeComponent();
}
public void buttonDoctorsDB_Click(object sender, EventArgs e)
{
doctorsDataGridView.DataSource = doctorsDataSet.Doctors;
doctorsDataGridView.Dock = DockStyle.Right;
if (Controls.Contains(patientsDataGridView))
Controls.Remove(patientsDataGridView);
if (Controls.Contains(hospitalsDataGridView))
Controls.Remove(hospitalsDataGridView);
this.Controls.Add(doctorsDataGridView);
}
public void buttonPatientsDB_Click(object sender, EventArgs e)
{
patientsDataGridView.DataSource = patientsDataSet.Patients;
patientsDataGridView.Dock = DockStyle.Right;
if (Controls.Contains(doctorsDataGridView))
Controls.Remove(doctorsDataGridView);
if (Controls.Contains(hospitalsDataGridView))
Controls.Remove(hospitalsDataGridView);
this.Controls.Add(patientsDataGridView);
}
public void buttonHospitalsDB_Click(object sender, EventArgs e)
{
hospitalsDataGridView.DataSource = hospitalsDataSet.Hospitals;
hospitalsDataGridView.Dock = DockStyle.Right;
if (Controls.Contains(patientsDataGridView))
Controls.Remove(patientsDataGridView);
if (Controls.Contains(doctorsDataGridView))
Controls.Remove(doctorsDataGridView);
this.Controls.Add(hospitalsDataGridView);
}
}
}
到目前为止一切都很好,但它带来的桌子都被“平滑”到了右边
我已经检查了自动调整大小,但还没有找到如何将它专门应用于我的代码。我希望它显示所有列,而不是只显示前两列,然后在 tha bootom 处给出一个滚动条。
我在这里假设自动调整大小是正确的方法,如果不是,请让我走上正确的道路。