问题描述
我想选中datagridview第一列中的一行,并删除,怎么做
解决方案
解决方案二:
privatevoiddatagridview1_cellclick(objectsender,DataGridViewCellEventArgse){index=e.RowIndex;if(index<0){return;}stringbookCode=this.dataGridView1.CurrentRow.Cells[2].Value.ToString();//获得ID值if(e.ColumnIndex==1){DialogResultdr;dr=MessageBox.Show("确定要删除吗?","",MessageBoxButtons.OKCancel);if(dr==DialogResult.Cancel){return;}dc.deleteDataBook(bookCode);//删除的方法DataTabledt=dc.getDataBook(getSql(),Convert.ToInt32(txtCurrentPage.Text.ToString()));//刷新数据dataGridView1.DataSource=dt;}
解决方案三:
privatevoidbutton2_Click(objectsender,EventArgse){//选中DGV中的第一行this.dataGridView1.Rows[0].Selected=true;}privatevoidbutton3_Click(objectsender,EventArgse){//从DGV中移除第一行this.dataGridView1.Rows.Remove(this.dataGridView1.Rows[0]);}