Hi,
In my usercontrol I bind the BindingSource I pass via property to all
the control inside the usercontrol.
For example
Control ctl=new TextBox();
ctl.DataBindings.Add("Text", binding, prop, false,
DataSourceUpdateMode.OnPropertyChanged);
via ANTS Profiler I see that it takes so much time and the UI seems
freeze (I have at least 10 controls to bind)
The behaviour slow down if I bind a combobox...
cmb.ValueMember = "Id";
cmb.DisplayMember = "Etichetta";
cmb.DataSource = binding;
cmb.DataBindings.Add("SelectedItem", binding, prop, true,
DataSourceUpdateMode.OnValidation, null);
at least 0,7 seconds for each control.
What is wrong? How can I speed up the binding task?
Thanks
Mauro
Nicholas Paldino [.NET/C# MVP] - 31 May 2007 14:23 GMT
Mauro,
There isn't much you can do, really. Remember, data binding uses
reflection to perform its operations, and that is inherently slower than
other methods.
The two things I can think of to speed up binding is to implement the
INotifyPropertyChanged interface, as it will not use reflection for change
notification on your type (assuming you are supporting it).
Second, for your properties that you are bound to, just make sure that
you are not doing a lot of heavy work in them (but that should be obvious).

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Hi,
> In my usercontrol I bind the BindingSource I pass via property to all the
[quoted text clipped - 23 lines]
> Thanks
> Mauro
Mauro D. - 31 May 2007 16:17 GMT
> Mauro,
>
[quoted text clipped - 9 lines]
> that you are not doing a lot of heavy work in them (but that should be
> obvious).
My class already implement the INotifyPropertyChanged interface...
My problem is not linked with a change in the property value but only in
the "startup time" of the binding.
Mauro
Marc Gravell - 31 May 2007 14:30 GMT
I'm not quite sure why it is *so* slow here, but if Nicholas is
correct (and reflection is the lag), you could try the following; this
improves the reflection -> component-model (i.e. what data-binding
uses) performance by a factor of roughly 180. Which is nice ;-p
http://www.codeproject.com/csharp/HyperPropertyDescriptor.asp
Marc