Hi
I have customised the XamDataGrid to add new row on click of a button outside the grid.
For this purpose i bind an observable collection to the grid.
The code in custom XamDataGrid to add a new row is as below
Public Sub AddRow(ByVal tempEntity As Object)
Try
Dim dataSource As IList = Me
.DataSource
dataSource.Add(tempEntity)
Me.DataSource = dataSource
Me.ExecuteCommand(DataPresenterCommands.RecordLastOverall)
intNewRowCounter = intNewRowCounter + 1
Me.ActiveRecord = Me
.Records(dataSource.Count - 1)
lstSelectedItems = New List(Of Object)
lstSelectedItems.Add(TryCast(Me.ActiveRecord, DataRecord).DataItem)
intPrevIndex = TryCast(MeEnableCellEditing().ActiveRecord, DataRecord).DataItemIndex
Me.FieldSettings.LabelClickAction = LabelClickAction.Nothing
RaiseEvent OnAdd(Me)
Catch ex As Exception
Throw ex
End Try
End Sub
Here the tempEntity is passed to the grid and is added to the Datasorce of the grid.
in this line of code
Me.ActiveRecord = Me.Records(dataSource.Count - 1)
i am setting the newly added row as the active one
This is working fine in the prototype i developed using trial cersion 8.2
but recently i bought the full version V 9.1 and this code is throwing error at the line above
The reason being Me.Records is not updated with the new count while the datasource is.
The exception was Index out of bounds.
The only thing not common to the development environment was the version.
could this be a bug.
Expecting a reply
Thanks in advance
Abhi
Hello Abhi,
On first look, this could be a possible issue. Could you please tell us which line exactly is causing the exception? I am also going to make a sample project in order to reproduce the issue using your code. If you have a sample, you could attach it so that we can look into it.
I will follow up here as soon as I was able to recreate the issue or not.
Regards,
Alex.
Hi Alex,
The problem occurs at this line :
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4
Before this the datasource is updated like this :
Dim dataSource As IList = Me.DataSource
It seems the datasource contents are getting updated and count increases on adding a new record but
XamGrid.Records collection is not,this was not the case in V 8.2 but its so in V 9.1.
However we have found a workaround for this
its this just before updating the datasource we set to nothing
Me.DataSource = Nothing