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:
  1. ' bind collection
  2.             Me.dataGridTeams.DataSource = Me.competition.teams
  3.             Me.competition.teams.BoundDataGrid(Me.dataGridTeams)
  4.             ' add grid handler
  5.             AddHandler Me.competition.teams.CountChange, AddressOf dataGrid_Update

VB Code:
  1. Private Sub dataGrid_Update(ByVal Sender As Object, ByVal e As CountEventArgs)
  2.         Me.dataGridTeams.DataSource = Nothing
  3.         Me.dataGridTeams.DataSource = Me.competition.teams
  4.     End Sub

VB Code:
  1. Private Sub btnTeamRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTeamRemove.Click
  2.         ' check item selected
  3.         If Me.dataGridTeams.CurrentRowIndex > -1 Then
  4.             Dim team As Team = Me.competition.teams.Item(Me.dataGridTeams.CurrentRowIndex)
  5.             If MsgBox("Are you sure you want to delete team " + team.ToString, MsgBoxStyle.OKCancel, "Delete Team") = MsgBoxResult.OK Then
  6.                 ' remove team
  7.                 Me.competition.teams.Remove(team)
  8.             End If
  9.         End If
  10.     End Sub