Good morning
in a RadGridView in the event of a button I delete a row from the database and I would like to reposition and select the row after the deleted one. The problem is that I can't figure out how to get the id of the row after the deleted one. To complicate things I add that the rows are filtered by the filtering row of the RadGridView. I attach code to make it clearer.
I think the problem is that to delete the row I take the index from the first cell of the row. But I don't understand how to take the index of the row of the radgridview
Fabrizio
Private Sub btnEliminaLotto_Click(sender As Object, e As EventArgs) Handles btnEliminaLotto.Click
'Trova id selezionato con ChildRows
propIdLottoMateriale = gridLottoMateriale.ChildRows(gridLottoMateriale.CurrentRow.Index).Cells(0).Value
Dim result As DialogResult
If Not (propIdLottoMateriale = Nothing) Then
If gridLottoMateriale.SelectedRows.Count > 0 Then
result = MessageBox.Show(" Sei sicuro di voler eliminare il Test Report N° : " & propIdLottoMateriale & " ? ", "Elimina test Report in Database", MessageBoxButtons.OKCancel)
If result = DialogResult.Cancel Then
Exit Sub
End If
If result = Windows.Forms.DialogResult.OK Then
EliminaLottoMateriale(propIdLottoMateriale)
'Controllo se il filtro esiste ancora
If (gridLottoMateriale.IsInEditMode) Then
gridLottoMateriale.EndEdit()
End If
'Toglie il filtro
gridLottoMateriale.FilterDescriptors.Clear()
'PopolaGridLotto()
'Aggiorna il dataset binding con la grid
TblNumeroLottoMaterialeTableAdapter.Fill(DsNumeroLottoMateriale1.tblNumeroLottoMateriale)
'Riposiziona la griglia sulla riga dopo quella eliminata
gridLottoMateriale.CurrentRow = gridLottoMateriale.ChildRows(indexRigaPerAggiorna + 1)
gridLottoMateriale.CurrentRow.IsSelected = True
Else
Exit Sub
End If
Else
MessageBox.Show("Seleziona una riga !!")
End If
Else
End If
End Sub
Public Function EliminaLottoMateriale(ByVal id As Integer)
Dim deleteCommand As DbCommand = Nothing
Dim rowsAffected As Integer
Try
deleteCommand = _db.GetStoredProcCommand("spDeleteQueryLotto")
_db.AddInParameter(deleteCommand, "id", DbType.Int32, id)
rowsAffected = _db.ExecuteNonQuery(deleteCommand)
Catch ex As Exception
MessageBox.Show("Errore EliminaLottoMateriale : " & ex.Message)
End Try
Return rowsAffected
End Function