I've come across a rather strange behavior.
Behind my form i have my constructor which looks like this:
Private Property SourceDatatable As DataTable
Public Sub New()
' This call is required by the designer.
InitializeComponent()
SourceDatatable = GetData()
'SourceDatatable now has 500 rows
AvailableObjects.DataSource = SourceDatatable
End Sub
Right now all 500 rows are visible inside the gridview. When the user clicks a button, then the selected row is 'copied'
Private Sub CopyObject_Click(sender As System.Object, e As System.EventArgs) Handles AddNewObject.Click
Dim selectedRow As Integer = GridviewAvailableObjects.GetSelectedRows().FirstOrDefault()
If (selectedRow > 0) Then
Dim selectedDataRow As Integer = GridviewAvailableObjects.GetRowHandle(selectedRow)
SelectedRecords.Rows.Add(SourceDatatable.Rows(selectedDataRow))
End If
GridViewSelectedValues.RefreshData()
End Sub
The error occurs at SourceDatatable.Rows(selectedDataRow)
. All of a sudden it has 0 rows
, Yet selectedDataRow
refers to the correct row in the datasource(datatable). There is no interference of other Methods/Code as these 2 methods are the only ones present on the form and there is no other code on this form
. Nor is the grid or any control accessible from outside the form.
What could cause this strange behavior? Does de Devexpress Gridview
do anything with the datasource?