Hi,
i found a nice little class on devcity called KeyedCollectionBase (http://www.devcity.net/Articles/66/1...llection.aspx). It claims to solve any problems with updating datagrids when using collections as the datasource.
But i can't seem to get it to work?????????
i bind the grid (dataGridTeams) to competition.teams (a TeamCollection Object, extends KeyedCollectionBase). Then tell the teamsCollection that it should be bound to the grid.
When I try to remove the last record in the datagrid it all goes belly up! And i get an index out of range error on the datagrid itself. It seems that for some reason the datagrid bindings aren't updating correctly, and I can't work out why. Any help would be great
VB Code:
' bind collection Me.dataGridTeams.DataSource = Me.competition.teams Me.competition.teams.BoundDataGrid(Me.dataGridTeams) ' add grid handler AddHandler Me.competition.teams.CountChange, AddressOf dataGrid_Update
VB Code:
Private Sub dataGrid_Update(ByVal Sender As Object, ByVal e As CountEventArgs) Me.dataGridTeams.DataSource = Nothing Me.dataGridTeams.DataSource = Me.competition.teams End Sub
VB Code:
Private Sub btnTeamRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTeamRemove.Click ' check item selected If Me.dataGridTeams.CurrentRowIndex > -1 Then Dim team As Team = Me.competition.teams.Item(Me.dataGridTeams.CurrentRowIndex) If MsgBox("Are you sure you want to delete team " + team.ToString, MsgBoxStyle.OKCancel, "Delete Team") = MsgBoxResult.OK Then ' remove team Me.competition.teams.Remove(team) End If End If End Sub





Reply With Quote