I have a DropDownList combo box loaded with 10 items. I have assigned this to teh WinTree.Override.EditorControl. Everything work fine and Editor control shows properly. However, when an item is selected in the combo box, events such as ValueChanged, SelectionChanged do not fire. The problem is that I want to do different things based on the SelectionIndex. However, it is always 0.
Something worng with my question or nobody knows the answer? :-)
When you assign a value to the EditorControl property, you are telling the UltraTree where to get its embeddable editor from. Using that embedded editor within the UltraTree will not cause the control's events to fire. The following code sample demonstrates how to handle the EditorWithCombo-specific events (in this example, SelectionChanged) that are raised by the embedded editor:
using Infragistics.Win;using Infragistics.Win.UltraWinEditors;using Infragistics.Win.UltraWinTree;
public partial class Form1 : Form{ private EditorWithCombo editor = null;
public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { // Add some nodes this.tree.Nodes.Add( "Node 1" ); this.tree.Nodes.Add( "Node 2" ); this.tree.Nodes.Add( "Node 3" );
// Add some items this.comboEditor.Items.Add( "Item 1" ); this.comboEditor.Items.Add( "Item 2" ); this.comboEditor.Items.Add( "Item 3" );
// Enabled editing, using an EditorWithCombo provided by the UltraComboEditor this.tree.Override.LabelEdit = DefaultableBoolean.True; this.tree.Override.UseEditor = Infragistics.Win.DefaultableBoolean.True; this.tree.Override.EditorControl = this.comboEditor;
// Hook the UltraTree's AfterActivate event this.tree.AfterActivate += new AfterNodeChangedEventHandler(this.tree_AfterActivate);
}
// Handles the UltraTree's AfterActivate event, for the purpose // of hooking the SelectionChanged event of the EditorWithCombo // associated with the ActiveNode. private void tree_AfterActivate(object sender, NodeEventArgs e) { UltraTreeNode node = e.TreeNode; if ( node == null ) return;
// If the editor hasn't changed since the last time we did this, // return since we are already listening to the right editor's event. EditorWithCombo editor = node.EditorResolved as EditorWithCombo; if ( this.editor == editor ) return;
// If we have a non-null editor reference, unhook its SelectionChanged event if ( this.editor != null ) { this.HookSelectionChanged( this.editor, false ); this.editor = null; }
// Set our reference this.editor = editor;
// Hook the event on the new editor if ( this.editor != null ) this.HookSelectionChanged( this.editor, true ); }
// Handles the EditorWithCombo's SelectionChanged event. private void editor_SelectionChanged(object sender, EventArgs e) { EditorWithCombo editor = sender as EditorWithCombo; object value = editor.Value; }
// Hooks/unhooks the EditorWithCombo's SelectionChanged event. private void HookSelectionChanged( EditorWithCombo editor, bool hook ) { if ( hook ) editor.SelectionChanged += new EventHandler(this.editor_SelectionChanged); else editor.SelectionChanged -= new EventHandler(this.editor_SelectionChanged); }
protected override void Dispose(bool disposing) { if ( disposing ) { if ( this.components != null ) this.components.Dispose();
// If we have a non-null editor reference, unhook its SelectionChanged event if ( this.editor != null ) { this.HookSelectionChanged( this.editor, false ); this.editor = null; } }
base.Dispose(disposing); }