如何在DataGridView中添加控件?使用Button事件。例如,我想在DataGridView中创建一个新的行和列,我想通过按钮控件发生。我该怎么做? 我正在使用C#.net和MS-Access。
答案 0 :(得分:1)
答案 1 :(得分:0)
这是一段用于将控件添加到gridview中的代码。
private void addNewRowButton_Click(object sender,EventArgs e) {
this.DataGridViewIssue.Rows.Add();//This line will add a new button contol into the grid
}
private void deleteRowButton_Click(object sender, EventArgs e)
{
if (this.DataGridViewIssue.SelectedRows.Count > 0 &&
this.DataGridViewIssue.SelectedRows[0].Index !=
this.DataGridViewIssue.Rows.Count - 1)
{
this.DataGridViewIssue.Rows.RemoveAt(
this.DataGridViewIssue.SelectedRows[0].Index);
}
}
private void SetupLayout()
{
this.Size = new Size(1055, 800);
addNewRowButton.Text = "Add Row";
addNewRowButton.Location = new Point(10, 10);
addNewRowButton.Click += new EventHandler(addNewRowButton_Click);
deleteRowButton.Text = "Delete Row";
deleteRowButton.Location = new Point(100, 10);
deleteRowButton.Click += new EventHandler(deleteRowButton_Click);
buttonPanel.Controls.Add(addNewRowButton);
buttonPanel.Controls.Add(deleteRowButton);
buttonPanel.Height = 50;
buttonPanel.Dock = DockStyle.Bottom;
this.Controls.Add(this.buttonPanel);
}