Hi, I have a multicolumn WinTree with the following properties,
ultraTree1.ViewStyle = ViewStyel.GridultraTree1.Override.SelectionType = SelectType.Extended;ultraTree1.FullRowSelect = false;
with these settings when a node is clicked it is getting activated and also Selected. However my requirement is to select the node only when either Ctrl or Shift key is pressed. Please suggest how to attain this functionality.
Thanks for any help,spm
I would imagine one solution to this problem would be to cancel the BeforeSelect event if the Ctrl or Shift key is not pressed.
Hi Brian,
Thanks for you reply. I tried your suggetion by storing the modifier status in KeyDown and KeyUp event and in BeforeSelect event e.Cancel was set to true if Ctrl or Shift key was not pressed. But unfortunatley the functionality did not work as expected, and at times selection were automatically deselected (.. it should be possible to select multiple nodes). Is there any other way of implementing this? Or have I done any thing wrong in my implementation. Please advice
Thanks,
spm
Unless I misunderstood what you are trying to accomplish, the following code solves the problem:
this.ultraTree1.Override.SelectionType = Infragistics.Win.UltraWinTree.SelectType.Extended;this.ultraTree1.BeforeSelect += new Infragistics.Win.UltraWinTree.BeforeNodeSelectEventHandler(ultraTree1_BeforeSelect);
void ultraTree1_BeforeSelect(object sender, Infragistics.Win.UltraWinTree.BeforeSelectEventArgs e){ bool control = (Control.ModifierKeys & Keys.Control) == Keys.Control; bool shift = (Control.ModifierKeys & Keys.Shift) == Keys.Shift;
if ( control == false && shift == false ) e.Cancel = true;}
I tried your solution in my project and it did not work, however when the same code was tried in the sample application it worked correctly. After some analysis the problem was found to be related to CellClickAction property, which in my code is set to EditCell, the solution given by you would work only if CellClickAction is SelectNodeOnly (i guess default behaviour of the tree). As a workaround for this the following was done,
1) In the KeyDown event if Ctrl or Shift key is pressed set CellClickAction property to SelectNodeOnlybool control = (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Control) == System.Windows.Forms.Keys.Control;bool shift = (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Shift) == System.Windows.Forms.Keys.Shift;if (control || shift) { this.Override.CellClickAction = Infragistics.Win.UltraWinTree.CellClickAction.SelectNodeOnly;}
2) and in the KeyUp event the same can be reset to EditCell, again if Ctrl or Shift is the key that was released bool control = (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Control) == System.Windows.Forms.Keys.Control; bool shift = (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Shift) == System.Windows.Forms.Keys.Shift; if (control == false && shift == false) { this.Override.CellClickAction = Infragistics.Win.UltraWinTree.CellClickAction.EditCell; }
3) finally in the BeforeSelect event the code given by you is used with minor modification so that when a cell is clicked in the abscense of either Ctrl or Shift key the entire selection is cleared. bool control = (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Control) == System.Windows.Forms.Keys.Control; bool shift = (System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Shift) == System.Windows.Forms.Keys.Shift;
if (control == false && shift == false) { try { this.EventManager.SetEnabled(Infragistics.Win.UltraWinTree.TreeEventIds.BeforeSelect, false); e.Cancel = true; this.SelectedNodes.Clear(); } finally { this.EventManager.SetEnabled(Infragistics.Win.UltraWinTree.TreeEventIds.BeforeSelect, true); } }
I hope this will be helpful to others. Also there was no possiblity of attaching the sample application along with this post, I feel that option would be great.
Thanks once again,