Why use databinding ?

  • Thread starter Thread starter LB
  • Start date Start date
L

LB

Reading the http://samples.gotdotnet.com/quickstart/winforms/
I'm trying to see the advantage of using "simple data binding".

Let's say I have a treeview loaded from a collection.
On form load, the treeview is loaded. And I bind my textbox to one on the
property
txtLength.DataBindings.Add("Text", moList, "Length")
On the TreeView1 click event, I add the following line :
Me.BindingContext(moList).Position = TreeView1.SelectedNode.Index
Everything is displayed on the form.

But why should I use the DataBindings.Add and BindingContext ?

Couldn't I use directly on the click event directly the following :
txtLength.text = moList.Item(TreeView1.SelectedNode.Index).Length

What's the advantage ?
Thank you for your time
 
LB,

When you have a lot of textboxes binded to a datasource, which is by
instance binded to a datatable, than you need only to know the position of
the datarow in that to let all textboxes be refreshed in one time by using
the position of the currencymanager (keeps track of the current datarow).

Therefore when you can get from your treeview that position, than is it of
course very easy to handle.

The most simple to think about binding is however when you have 4 position
buttons.
First, previous, next, last what than is
position = 0
position -= 1
position +=1
position = .count - 1

I hope that this gives an idea.

Cor
 
Back
Top