views:

60

answers:

1

Hi guys,

I have a data grid loading row event

_gridObj.LoadingRow += new EventHandler<DataGridRowEventArgs>(_gridObj_LoadingRow);

and in the handler I am creating another event. In the following code how can I know if the MouseLeftBtn event already exists for that row?

void _gridObj_LoadingRow(object sender, DataGridRowEventArgs e)
{
    e.Row.MouseLeftButtonUp += new MouseButtonEventHandler(Row_MouseLeftButtonUp);
}

Thanks,

Voodoo

+2  A: 

Based on your comment that you don't want to attach muliple handlers in this case I unsubscribe then resubscribe. It does not give an error unsubscribing if none exists and ensures only one handler.

void _gridObj_LoadingRow(object sender, DataGridRowEventArgs e)
{
    e.Row.MouseLeftButtonUp -= new MouseButtonEventHandler(Row_MouseLeftButtonUp);
    e.Row.MouseLeftButtonUp += new MouseButtonEventHandler(Row_MouseLeftButtonUp);
}
aqwert
+1, thanks your way seemed to have worked.
VoodooChild