私は、DataGridViewでDeleteItem機能を実装しようとしています。 私は次のイベントがあります。DataGridViewの行インデックスは常に同じ値を返します
private void btnDeleteDjelatnik_Click(object sender, EventArgs e)
{
int idDjelatnik = -1;
int index = djelatnikDataGrid.CurrentRow.Index;
Int32.TryParse(djelatnikDataGrid.Rows[index].Cells[0].Value.ToString(), out idDjelatnik);
r.DeleteDjelatnik(idDjelatnik);
}
私は私が私のDeleteメソッドに渡すことができるように選択された行ID列を取得しようとしている:DeleteDjelatnik(int型slectedID)。
次の行は、常に私の3の値を与える:
int index = djelatnikDataGrid.CurrentRow.Index;
私も
int index = djelatnikDataGrid.SelectedRows[0].Index;
を試してみましたが、私はArgumentOutOfRange例外を取得しています、はい、私のselectionModeがFullRowSelect
どうでありますこれを機能させるには?
try datagridview.CurrentCell.RowIndex –
'CurrentRow'と' SelectedRow'は同じではないかもしれません。 'CurrentRow'はセルがアクティブである行を返します。 'SelectedRows'は選択を返します。したがって、' djelatnikDataGrid.SelectedRows [0] 'を使用する必要があります。 –
私はすでにdatagridview.CurrentCell.RowIndexを試していましたが、私は何の行を選択しても値3を取得します。/ – ChenChi