No event is firing when placing a custom data bound control in DataRepeater control in Windows forms
- by Remo
Hi,
Custom events in a custom data bound control are not firing in DataRepeater control. When I debug it I found that the DataRepeater Control recreates the control using Activator.CreateInstance and Copies the Properties and Events. In my case copying events doesn't copy the custom events that I hooked in.
For example
public class MyClass : Control
{
public event EventHandler MyEvent;
protected virtual void OnMyEvent()
{
if(this.MyEvent != null)
{
this.MyEvent(this,EventArgs.Empty);
}
}
private int selectedIndex= -1;
public int SelectedIndex
{
get
{
return this.selectedIndex;
}
set
{
if(this.selectedIndex != value)
{
this.selectedIndex = value;
this.OnMyEvent();
}
}
}
//
// DataBinding stuff goes here
//
}
public Form1()
{
InitialiseComponent();
ArrayList list = new ArrayList();
list.Add("one");
this.dataRepeater1.DataSource = list; // One Repeater
MyClass test = new Myclass();
test.DataSource = GetDataTable();
this.dataRepeater1.ItemTemplate.Controls.Add(test);
test.MyEvent +=new EventHandler(test_MyEvent);
}
// This Event should fire when selected index of Datatable is changed and is firing when placed directly in the form and not firing when place in DataRepeater control///////////////////////
private void test_MyEvent(object sender, EventArgss e)
{
// This event is not fired///////////////////////
}
private DataTable GetDataTable()
{
..// Create a data Table and return
}
Any help Appreciated.
Thanks,