How to add multiple keystrokes to a TreeView node? #3589
Answered
by
tznind
Andras-Csanyi
asked this question in
Q&A
-
I'd like to add multiple keystrokes to a TreeView node achieve something like the following:
I am reading the API of the TreeView and View and it seems this is not possible, because only the Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
tznind
Jul 7, 2024
Replies: 1 comment 2 replies
-
Here is an example of using the // Prevent selecting many objects at once
tv.MultiSelect = false;
// Disable normal activation key
tv.ObjectActivationKey = Key.Null;
tv.KeyPress += (e) =>
{
// Use 'as' your class here or do conditional checks
var o = tv.SelectedObject as FileSystemInfo;
if (o == null)
{
return;
}
if (e.KeyEvent.Key == Key.A)
{
e.Handled = true;
MessageBox.Query("Last Write", o.LastAccessTime.ToString(), "Ok");
}
if (e.KeyEvent.Key == (Key.Enter))
{
e.Handled = true;
MessageBox.Query("Full Path", o.ToString(), "Ok");
}
if (e.KeyEvent.Key == Key.R && o is FileInfo f)
{
e.Handled = true;
MessageBox.Query("Length", f.Length + " bytes", "Ok");
}
}; |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Andras-Csanyi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is an example of using the
KeyPress
event to perform different actions in aTreeView<FileSystemInfo>
.