Hi,
I'm using a treeview as a menu, and when the user clicks on a node I
want the focus to set to a control (ie textbox) in a panel to the
right. The problem I'm having is the focus will not stay on the
control, but instead jumps back to the treeview.
I'm setting the focus in the AfterSelect event of the treeview, and if
I step through the code the desired control does have .Focused = True
after I have set it, but then somewhere after the AfterSelect event the
focus changes back to the listview. I have no other code after the
focus is set to the control.
Is there a better event I should be doing this in, or something else I
need to do to stop the focus jumping back to the treeview.
Regards,
Mong 1 6369
Mong,
I was having a similar problem in an app and my workaround may or may
not work for you. If you put the thread to sleep for a second during
the TextBox.GotFocu s event you'll see that the TreeView hasn't fully
updated when the AfterSelect is fired. The node you click is still
highlighted in gray instead of the dark blue. I'm assuming this is
part of the reason it steals the focus back - to redraw itself.
My method.
I have a generic handler, FocusHandler( ) that handles the GotFocus
event for all the controls that get focus from the TreeView. I set a
form-level boolean (GiveMeBackMyFo cus) to true in this Handler.
In the TreeView.GotFoc us event, I check this boolean. If it's set to
True, then the TreeView gives control back and sets it to False to
prevent it from firing again.
I track the control that needs focus with a form-level
System.Windows. Forms.Control variable that is set during the
AfterSelect event.
Here's a quick example of how I implemented it:
Public Class Form1
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "
#End Region
Private textBoxNode As TreeNode
Private listNode As TreeNode
Private otherNode As TreeNode
Private GiveMeBackMyFoc us As Boolean
Private controlToFocus As Control
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
textBoxNode = Me.TreeView1.No des.Add("TextBo x Node")
listNode = Me.TreeView1.No des.Add("Listbo x Node")
otherNode = Me.TreeView1.No des.Add("Other Node")
End Sub
Private Sub TreeView1_After Select(ByVal sender As System.Object,
ByVal e As System.Windows. Forms.TreeViewE ventArgs) Handles
TreeView1.After Select
If e.Node Is textBoxNode Then
Me.controlToFoc us = Me.TextBox1
ElseIf e.Node Is Me.listNode Then
Me.controlToFoc us = Me.ListBox1
Else
Return
End If
Me.ActiveContro l = Me.controlToFoc us
End Sub
Private Sub FocusHandler(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles TextBox1.GotFoc us, ListBox1.GotFoc us
Me.GiveMeBackMy Focus = True
End Sub
Private Sub TreeView1_GotFo cus(ByVal sender As Object, ByVal e As
System.EventArg s) Handles TreeView1.GotFo cus
If Me.GiveMeBackMy Focus Then
Me.controlToFoc us.Focus()
Me.GiveMeBackMy Focus = False
End If
End Sub
End Class
John This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Franck Pommereau |
last post by:
Hi all,
I'm building a PyGTK interface in which I would like that no widget
would be able to get the focus (and so to be activated by pressing the
Return key). For this purpose, for each widget, I do:
widget.set_property("can-focus", gtk.FALSE)
My problem is a TreeView which has a clickable column, it get the
default focus and I did not find how to forbid that.
|
by: Dave |
last post by:
I use the treeview to open a new form but the treeview reclaims focus after
MouseUp. Any solutions to this problem?
|
by: (Pete Cresswell) |
last post by:
I've got a TreeView on the left of my screen. As the user navigates the tree, I
load corresonding detail info into the rest of the screen.
Works ok, but when the user clicks on a detail field, the TreeView's selection
rectangle goes away and the user is left wondering what happened.
Seems like there ought TB a way to preserve that rectangle. The optimal would
be to have it go grey when the control loses focus and return to blue whe...
|
by: Rasmus |
last post by:
I need to grab focus to a specific node i my treeview when I click on my listbox.
Here's the code that differs between the different event i the listBox:
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string selected;
selected = this.listBox1.SelectedItem.ToString();
if(selected == "Error in Supercell 1")
{
|
by: Stephan Rose |
last post by:
Ok here's my situation...
Got an MDI application with a panel to my right that has a tree view
for the project stuff, etc.
Now if I select an item in the tree view, the tree view gains input
focus. After this happens, my MDI children no longer are able to
obtain keyboard focus and therefore no longer receive keyboard
commands. Needless to say, that's a bad thing. :)
| |
by: Elliot |
last post by:
The following code creates 2 node objects in a treeview control. When
I click on the second node, a process object corectly launches
"http://www.cnn.com" but focus immediately returns to the treeview
control. It shouldn't. It should stay with the Internet Page. The Page
is being launched from the AfterSelect Event, could that be causing the
treeview control to get focus again?
Any help would be appreciated.
Thanks,
|
by: Kay |
last post by:
Hi all,
Can anyone tell me how do I set focus on a particular treenode at run time?
If you need to know what I'm try to do please read on ...
I have a treeview to represent a Country/Product scenario (i.e. a country,
as parent node, produce 1 to many product, as childnode). When the user
click on one of the node a group of textbox/combo box etc will be populated
and if btnSave is clicked data will then be updated and the treeview will...
|
by: Fr15ky |
last post by:
First of all, I am using the .NET 2.0 framework with Visual Studio
2005.
I have two forms. One is a form with a TreeView control on it (used as
a menu - kindof a favorites list) and the other is a form with a
WebBrowser control on it.
The TreeView_Click event fires up the other form with the link passed
to it via the Node. If the user clicks the TreeView and the form is
already open with that link in it, it is supposed to set focus to...
|
by: Tee |
last post by:
Hi,
In my C# application i have a treeview control and listview control, the
treeview is on the left side of the from and the listview is on the right.
When i click on an item in treeview i got code to force the listview to
selected the appropriate item and set focus on the listview, but the focus
never work it always stay on the treeview control.
Here my sample code
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |