DataGrid and Add/Remove Handler

mafrosis

Well-known member
Joined
Jun 5, 2006
Messages
88
Location
UK
Programming Experience
5-10
Hey all, Im doing a bit of .NET 1.1 atm and have the situation where I want to parse text entered into a cell on a datagrid. See the code:

VB.NET:
[COLOR=Blue]Private Sub[/COLOR] dgPlayers_ItemChanged([COLOR=Blue]ByVal [/COLOR]sender [COLOR=Blue]As [/COLOR]System.Object, [COLOR=Blue]ByVal [/COLOR]e [COLOR=Blue]As [/COLOR]System.Windows.Forms.ItemChangedEventArgs) [COLOR=Blue]Handles [/COLOR]cm.ItemChanged
    [COLOR=Blue]If [/COLOR]dgPlayers.CurrentCell.ColumnNumber = CAREER_SCORE_COL_INDEX [COLOR=Blue]Then[/COLOR]
[COLOR=Green]        'generate new cs string[/COLOR]
        [COLOR=Blue]Dim [/COLOR]cs [COLOR=Blue]As String[/COLOR] = ParseCareerScoring(ds.tbl_players.Rows(e.Index)("career_scoring"))
            
        [COLOR=Green]'suppress this event[/COLOR]
        [COLOR=Blue]RemoveHandler [/COLOR]cm.ItemChanged, [COLOR=Blue]AddressOf [/COLOR]dgPlayers_ItemChanged

        ds.tbl_players.Rows(e.Index)("career_scoring") = cs

        [COLOR=Green]'re-add the handler[/COLOR]
        [COLOR=Blue]AddHandler [/COLOR]cm.ItemChanged, [COLOR=Blue]AddressOf [/COLOR]dgPlayers_ItemChanged
    [COLOR=Blue]End If
End Sub[/COLOR]
I had to remove and then add the event handler around setting the datasource otherwise the event gets handled a second time.

Is there overhead in adding/removing handlers in this fashion? Or is there a better way of achieving the same effect?

Thanks
mafro
 
Back
Top