在C#中删除DataGridView中的最后一行按钮,可以按照以下步骤进行操作:
DataGridViewButtonColumn deleteButtonColumn = new DataGridViewButtonColumn();
deleteButtonColumn.HeaderText = "删除";
deleteButtonColumn.Text = "删除";
deleteButtonColumn.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(deleteButtonColumn);
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == dataGridView1.Columns["删除"].Index && e.RowIndex != -1)
{
dataGridView1.Rows.RemoveAt(e.RowIndex);
}
}
dataGridView1.CellClick += dataGridView1_CellClick;
完成以上步骤后,当用户点击DataGridView中的删除按钮时,最后一行数据将被删除。
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云