0

I am using databinding in my winforms project, but setting the DataSource property takes a few moments:

eventBindingSource.DataSource = _event;

I've tried setting the SuspendBinding() and ResumeBinding() methods, but this didn't make the binding faster.

Do you have any ideas to speed up the data binding?

Also when I edit a control, it goes very slow.

I am using Winforms, C# and the Entity Framework and _event is a POCO class with about 20 properties.

Martijn
  • 24,441
  • 60
  • 174
  • 261
  • If you pre-set the datasource in the designer as the expected type does it speed things up? That way you'll get better designer binding support too if you want it... – Reddog Feb 19 '12 at 21:52
  • @Reddog What do you mean by 'pre-set the datasource in the designer'? In the designer I have created the datasource and bound the properties to the controls – Martijn Feb 19 '12 at 21:53
  • Is _event in memory or lazy loaded from the database when first accessed? – Joachim Isaksson Feb 19 '12 at 21:55
  • In the winforms designer, you should be able to select the BindingSource component (down the bottom) and set it's datasource by adding a "Project Data Source" that is defined for your `Event` object type. While this won't actually get rid of the delay (which presumably happens while it's reflecting your class' properties), it might move it to form start up instead thus changing the perceived delay. – Reddog Feb 19 '12 at 21:57
  • @JoachimIsaksson _event is created in the ctor of the form with `_event = new Event()` all the subproperties are also created this way, i.e.: `_event.ContactAddress = new Address()` – Martijn Feb 19 '12 at 21:58
  • @Reddog The `DataSource` property contains this value in design time: `EventManager.CoreLibrary.Entities.Event` – Martijn Feb 19 '12 at 22:00
  • Hmmmm, that means it's already configured. Well, that counts my hunch out... Sorry! – Reddog Feb 19 '12 at 22:05
  • @subt13 I am not familiar with VS profiler. Hoe can I use this? – Martijn Feb 19 '12 at 22:22
  • @Martijn - you should read up on it, it is very useful. Even tells how long SQL queries take. I go to the Analyze menu at the top -> Launch Performance Wizard. – O.O Feb 19 '12 at 22:32
  • @subt13 Thanks, I just did, but I don't know what I can do with the information. This is what I get: ThreadContext.RunMessageLoop 79,42 1,71 and Forms.Main..ctor() 20,53 0,00 – Martijn Feb 19 '12 at 22:39

2 Answers2

1

I suggest you install a profiler (there are free ones) and find out exactly what's taking the time. It will prevent any guesswork and you'll learn a lot about what is going on under the covers.

  • Paid: ANTS and dotTradre
  • Free: Equatec and SciTech

VS 2010 comes with one too if you have a high enough edition (can't remember which).

All linked from from this answer

Community
  • 1
  • 1
Steven P
  • 1,956
  • 1
  • 16
  • 17
0

Turn of all auto sizing of DataGridView first, then set DataSource property, and set up your auto sizing preferences back. This really boost the power of DataGridView.

Fanda
  • 3,760
  • 5
  • 37
  • 56