View previous topic :: View next topic |
Author |
Message |
flc.net
Joined: 21 Jun 2005 Posts: 89 Location: Switzerland
|
Posted: Thu Jun 23, 2005 1:38 pm Post subject: BindingContext ? |
|
|
Hi
Is it possible to keep syncronized Virtual Tree with other Controls assigning the same BindingContext? --> Like DataGrid (ComplexBinding for Navigation) and a lot of Controls (SimpleBinding for displaying/editing all Details values).
Thanks and Best Regards
Giuseppe |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Jun 23, 2005 11:17 pm Post subject: |
|
|
Currently VirtualTree does not track the binding context CurrencyManager(s) CurrentChanged event nor does it set this. This is for performance reasons - because a tree may consist of thousands (or millions) of individual list data sources - each of which would require its own CurrencyManager to use this mechanism.
We are considering implementing this for the root list data source so that if you are using VirtualTree as a non-hierarchical listview you can make use of this functionality.
It is actually easy to implement this functionality yourself by simply handling the SelectionChanged event (or overriding the OnSelectionChanged) method and adding the following code.
Code: |
private void _virtualTree_SelectionChanged(object sender, System.EventArgs e)
{
object selectedItem = _virtualTree.SelectedItem;
// assuming your data source is a simple list
//
IList dataSource = _virtualTree.DataSource as IList;
CurrencyManager cm = (CurrencyManager)BindingContext[dataSource];
if (selectedItem == null)
cm.Position = -1;
else
cm.Position = dataSource.IndexOf(selectedItem);
}
|
In general however the binding context mechanism is not well suited to the hierarchical nature of the tree and you are probably better just handling the selection event directly and binding the forms controls directly to the newly selected object eg:
Code: |
private void _virtualTree_SelectionChanged(object sender, System.EventArgs e)
{
object selectedItem = _virtualTree.SelectedItem;
if (selectedItem is Customer)
{
// _lastNameText and _firstNameText are textbox controls
//
this._lastNameText.DataBindings.Add(new Binding("Text", selectedItem, "LastName"));
this._firstNameText.DataBindings.Add(new Binding("Text", selectedItem, "FirstName"));
}
}
|
_________________ Infralution Support |
|
Back to top |
|
|
Guest
|
Posted: Fri Jun 24, 2005 6:27 am Post subject: |
|
|
thanks for the fast and detailed answer.
you have very a fantastic support!
best regards
giuseppe |
|
Back to top |
|
|
|