3

I have VirtualTreeView with 3 columns (column headers are invisible if that matters).

When I press F2 (default key to start editor) to edit a node it edits node in column 0. How can I switch it to edit node in column 1 instead?

Something of an equivalent of this code but for F2 key:

VST.EditNode(VST.GetFirstSelected(), 1);

Coder12345
  • 3,431
  • 3
  • 33
  • 73
  • Some things I don't understand: first, if the column is invisible, how will anyone edit it? Second, are you saying that that line of code does what you want, but that the problem is merely about how to tie that command to the F2 keystroke? Or was there more to the problem? – Rob Kennedy Feb 25 '14 at 05:51
  • 2
    You need `toExtendedFocus` in `TreeOptions.SelectionOptions`. Then you can move the focus to the 2nd column and F2 will switch to Edit mode in that column. If you also add `toGridExtensions` to `TreeOptions.MiscOptions` you can move around the focus with the Keyboard. – Stefan Glienke Feb 25 '14 at 07:58
  • @RobKennedy He might mean column headers are invisible? – David Feb 25 '14 at 10:51
  • Column headers are invisible not the columns. Sorry about that. F2 is the default key for starting editor in VirtualTreeView so not something I added. So the problem is that F2 key opens editor but for the first column data not the second where is the actual data to be edited. I can open editor for the second column data with above code but F2 still edits it for first column. I will try the `toExtendedFocus` and report back. – Coder12345 Feb 25 '14 at 21:00
  • @StefanGlienke: `toExtendedFocus` does work but now the problem is different - now all columns can be edited with F2 key (including the first and last column). Is there a way to stop editing of all columns except of course the second one (index = 1)? – Coder12345 Feb 25 '14 at 21:14
  • I did it using the `OnEditing` event and set `Allowed` to false if column is anything other than 1. Thank you all for your help. @StefanGlienke - If you want to write a quick answer I'll be glad to mark it as correct, otherwise, I'll write it myself. – Coder12345 Feb 25 '14 at 21:57

1 Answers1

7

You have to set toExtendedFocus in TreeOptions.SelectionOptions to be able to focus the column and then change to edit mode using F2 or clicking a selected cell again.

If you want to navigate using the keyboard you also have to set toGridExtensions to TreeOptions.MiscOptions.

To prevent certain columns from being edited you have to implement the OnEditing event of the treeview and set Allowed to False for those that should not be editable.

You can also exclude coAllowFocus from Options for those columns to prevent focusing them (and thus making them not editable).

P.S. I will propose adding coEditable to TVTColumnOption on the VTV.

Stefan Glienke
  • 20,860
  • 2
  • 48
  • 102