Databinding takes high time

M

Mauro D.

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
 
N

Nicholas Paldino [.NET/C# MVP]

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).
 
M

Mauro D.

Nicholas said:
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).

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top