Releasing an Event

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

Hello,
I've got a table and I create a tablestyle for it. This table is the
datasource for a dataGrid. In this createTableStyle function one of the
columns is a button. I tie a button to it.
buttonColStyle = new DataGridButtonColumn(i);

and a click event.
buttonColStyle.CellButtonClicked += new
DataGridCellButtonClickEventHandler(HandleCellButtonClick);

In the HandleCellButtonClick function, it calls another form.

This all works fine.except.

My problem is that on my main form I have a button which will pull new data
from a database and rebuild the table and tablestyle for the table. So, when
the above code is executed again, it ties another CellButtonClicked event to
the button. So now when I click the button in the datagrid and the form
comes up, I have to close it twice to get rid of it.
I've tried dataGrid1.TableStyles.Clear(); to maybe release it but that doesn
't work. Can someone tell me how to clear the events tied to a tableStyle?
Thanks to all...
 
Hi,

try using buttonColStyle.CellButtonClicked -= new
DataGridCellButtonClickEventHandler(HandleCellButtonClick) to unsubscribe
the event from the delegate.

Regards
Joyjit
 
Back
Top