I have a form with a grid and a combo box where a user can select the table name they wish to edit. I have the grid binding to the table name selected by calling Rebind() when the user makes a table name selection, and by handling the NeedDataSource event of the grid to bind to a DataTable. That seems to work fine.
The problem comes in when I try to edit. I added a GridEditCommandColumn to the MasterTableView's Columns collection so I get a link to start editing a row, and the editor form appears just fine. But when I click on 'update', and I try to handle the UpdateCommand event raised by the grid (from code cobbled together from forums), I get an argument out of range exception, that I believe is coming from the edited item's OwnerTableView.DataKeyValues collection which has zero elements.
One other thing to note, I am using Postgres as the database, but I don't think this is the issue, as I am using npgsql to get standard ado.net objects to bind to.
Any ideas?
Private Sub RadGrid1_UpdateCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem) Dim table As DataTable = Me.GridSource 'Locate the changed row in the datasource Dim pk As String = GetPrimaryTablePKColumn(cboTable.Text) If pk Is Nothing OrElse pk.Trim = String.Empty Then e.Canceled = True Return End If 'Error Happens Here Dim changedRows As DataRow() = table.Select(pk & " = " & editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)(pk).ToString) If changedRows.Length <> 1 Then e.Canceled = True Return End If 'Update new values Dim newValues As New Hashtable e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem) changedRows(0).BeginEdit() Try For Each entry As DictionaryEntry In newValues changedRows(0)(DirectCast(entry.Key, String)) = entry.Value Next changedRows(0).EndEdit() Catch ex As Exception changedRows(0).CancelEdit() e.Canceled = True End Try