|
I've got a Treeview for item selection / association and another control for editing / validating the selected item. These form a composite control responsible for managing the Items collection. There are a number of similar style controls (View / Editor combo) with responsibilities for different parts of the application data beside items. These all sit on an observable model which can be modified and kept in sync with the various views and handle the Undo/Redo commands.
I'm trying to get the manager control to handle the Selected event in the tree view / list and pass the focus to the editor control, which in turn would focus on it's main field so the user can edit and tab through the various controls without having to click on it first.
I'm hoping to make this the default behavior for each view, but for some reason the Focus event gets eaten by the Custom control.
EDIT: Ok - so it IS shifting focus, but it's not raising an event or the OnFocus method, and i have no control over what it selects. I thought it was tab index, but it doesn't do anything that i can see.
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
modified on Tuesday, April 7, 2009 8:05 AM
|
|
|
|
|
Ok, now I recognize that I can't understand the design as you are stating it.
Tristan Rhodes wrote: There are a number of similar style controls (View / Editor combo)
Tristan Rhodes wrote: These form a composite control
Tristan Rhodes wrote: I'm trying to get the manager control to handle the Selected event in the tree view / list and pass the focus to the editor control
So if this "editor control" is one of your custom controls you should say that rather than editor control which is interpreted as edit control, hence much confusion.
Anyway if I now understand correctly, don't use the focus event. If this is your custom control, in fact they all are I guess, you should have a design that is yours. It could be events or messages it doesn't matter but it should be yours. Don't try to use the framework events as your custom events, that is probably not a great idea even when it works.
This is not a topic I remember Kent Beck covering in Implementation Patterns, but I imagine he would say something like "prefer explicit design to implicit" as it is easier to understand.
|
|
|
|
|
Hi Mike,
I'm not trying to use any custom events, i just want to be able to handle a change of focus on my control so i can implement some specific behavioral logic. It's not (or shouldn't be) a complicated task. I'm happy with the application design as is, and I don't really want to have to implement my own system for something that already exists that just needs a bit of custom tailoring.
To sum up the process:
* User selects MenuItem in treeview
* TreeView raises selected item change
* Selected MenuItem is loaded into MenuItemEditor
* Focus is passed to MenuItemEditor
* MenuItemEditor passes focus to TextBox. //OnFocus / Focus event not hit
* User edits TextBox Text.
Regards
Tris
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Are you handling an event or overriding OnFocus? If you are overriding the method, do you still call base.OnFocus()?
|
|
|
|
|
I override the OnFocus method as the event wasn't getting raised. The OnFocus method never gets hit either for some reason.
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
You'll have to research this a bit I'm afraid. For some reason (there must be something better than anything I can think of) Microsoft has this incredibly elaborate design for this stuff which means simple logical code you'd expect to work just doesn't.
Unfortunately it seems that the TreeView is doing something *after* the *After*Select event that causes the active control to be reset to whatever tree node you were working with.
It's not elegant, but I worked around it using a Timer control and an instance member to refer to the control I want to activate, a la this:
Control ctrlToActivate;
void timer1_tick(object sender, EventArgs e)
{
if (ctrlToActive == null) return;
ctrlToActivate.Select();
ctrlToActivate = null;
}
void tree_afterSelect(object sender, TreeViewEventArgs e)
{
tabControl1.SelectedIndex = int.Parse(e.Node.Tag.ToString());
foreach (Control c in tabControl1.SelectedTab.Controls)
if (c is TextBox) { ctrlToActivate = c; return; }
}
The timer event is on the UI main thread so basically the message loop of the window will call the handler whenever it's doing an iteration and finds that the timer's interval has expired. It's not really expensive so you can use a short interval like 30 milliseconds, but there surely ought to be a much easier way to achieve this. I can only suggest you study the model because clearly focus and selection and "currently active control" are related but not identical concepts.
Finally, a word on terminology. I wouldn't call this bubbling. Your control is a container that when receiving focus (or perhaps when "being activated" which apparently is not the same thing) should in turn activate/focus a particular child control. Bubbles rise - and I think most people think of event bubbling the way it works in DHTML: An event occurs on a control, and if there's a handler registered with the control for the event it executes. Then the event may bubble to the parent control of the "event source", and again handlers may execute. This allows the user to attach a handler to a container and handle events that originate in the child controls - such as a mouse click anywhere in a table without having to register handlers with every row, cell, and content controls inside it. What you're doing is pretty much the opposite - you're not bubbling an event to a handler somewhere up the control tree, but rather "rippling the event" or causing a domino effect so that when the event occurs on the parent it also occurs on a child.
I'm fairly amazed at how complicated Microsoft sometimes manages to make even the functionally/conceptually simplest of tasks. To be fair, with .net they've often made it easy to do formerly complicated things, but this is frankly ridiculous. Trying to find anything in the documentation is awful - you have to take bits and pieces from Control, ContainerControl, the IContainerControl interface for container controls that don't inherit from ContainerControl (such as the TabPage, which inherits from Panel, ScrollableControl, Control, object -- meaning the Panel isn't a ContainerControl either..!?!), Form.ActiveControl, and more, and consolidate the reference-style information here into something that resembles a logical model for controlling what control is active in your application. Maybe the nature of the problem really is so intricate and complex that this is to be expected, or maybe Microsoft did a truly bad job with this part of the FrameWork. Or maybe (my real hypothesis) it is necessary to conform to certain *windows* (as opposed to .net) concepts that are hideously complicated and make it impossible to come up with a simple way to activate a textbox when a user clicks a node in a tree. One would not think this should be hard, but just google for Focus() and Select() and "active control" and "set focus .net windows forms" and you'll quickly see that a LOT of people are finding this a daunting task.
|
|
|
|
|
I did some digging and realised that the focus was changing, but changing back again. It swapped focus OK when i right clicked and the ContextMenu comes up, but if i Mouse Down, the focus changes, and MouseUp it changes back again. A real pain.
In addition, the OnFocus doesn't get called anywhere. Argh, i hate UI stuff, it takes up 80% of the development time to get the event system working just the way the end user wants Thankfully it's not an urgent priority, so i'm, going to put it on a back burner.
Cheers for the pointers though.
And how about focus cascading? I Wasn't sure what to call it and i'd just watched Finding Nemo
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Hi Guys,
I'm having problems with Process.Start, if i give it just the .exe path, it works fine, if i try to add a following string after it to specify a file to be opened by the .exe, it throws a FileNotFound exception in .Net.
i.e:
Ok -
Process.Start("C:\\Temp\\My.exe");
File Not Found -
Process.Start("C:\\Temp\\My.exe \"C:\\Temp\\MySampleFile.xml\"");
Both files exist, it works fine if i copy it into Command line or use Run.
Any idea how to get around this?
Cheers
Tris
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
|
DOH!
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Hi,
I have 2 websites build in .NET hosted on same server, using same database SQL Sever 2005.
Now when I browse through in any of these sites, after randomly browsing through different page, the site gets hanged and after few minutes I got Time Out error.
The Description of error is as follows
The following error was encountered:
* Read Timeout
The system returned:
[No Error]
A Timeout occurred while waiting to read data from the network. The network or server may be down or congested. Please retry your request.
Please help, I was struck into this since last couple of days.
|
|
|
|
|
Okay - So you have to decide how you want your application to react when it receives a time out error. I would suggest you either allow it to gracefully degrade the functionality (if the specific feature is a nice-to-have) or inform the user that their request could not be honoured.
If it is happening in SQL Server you may want to consider optimising your queries or database if that is taking a long time to return answers to your queries.
|
|
|
|
|
Hi,
I need to know that, is .net framework required to run a windows service, which was created using Visual Studio 2005?
Thanks in advance...
Subin.
|
|
|
|
|
Yes, the framework is required to run .NET assemblies
I are troll
|
|
|
|
|
Not if you used Visual Studio 2005 to write it in unmanaged code.
|
|
|
|
|
There is an interesting project:
www.codeproject.com/KB/IP/Modbus_TCP_class.aspx
Could someone please tell me what software I need to open and run this project code? Obviously, I have given myself away as someone who knows very little about programming. Actually, I have quite a lot of experiance with VB6 so I am nota complete novice.
Thanks in Advance,
Johnny
|
|
|
|
|
Hi,
the article's header and download indicate it was programmed in C# using Visual Studio 2003, which got superseded by VS2005 and later by VS2008. If you don't have any of those available, the best you could do is download the free "Visual Studio 2008 C# Express Edition" from the Microsoft website (it needs the .NET Framework 3.5 present on your development system; that too is freely downloadable).
When launching the project, it will convert it to the latest file format automatically; from then on it should work as intended.
Assuming you are unfamiliar with both the .NET Framework and the C# programming language (a successor to object oriented languages such as C++ and Java) I strongly suggest you buy a tutorial book on C# and study that before you start any C# programming yourself.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi Luc,
Thanks for the excellent response. I will do as you suggest.
Regards,
Johnny
|
|
|
|
|
Hi, I am working on a project on Windows Azure Platform....
Does anyone know any good tutorial on this platform?
I want to make a project via Azure Services Developer portal and I want to publish it so it would be available to everyone...
At last, I'd like to make a project in VS 2008 about Cloud Service Web & Worker role to be published, but I couldn't find a good tutorial-example on how to do that, since I am new to these technologies...
Any help would be appreciated.
|
|
|
|
|
|
|
anyone knows how to compile monodevelop from sourcecode with mingW on windows?
I have mono installed, monodevelop source, and mingw installer but I don't know how to use it
Thank's
(sorry if i posted in wrong place, I don't see other place fit)
No one can prevent me to learn something
|
|
|
|
|
Type.GetType("System.Enum").IsClass returns false, yet all the documentation indicates that System.Enum is a class. What am I missing?
|
|
|
|
|
You're not missing anything, it's just that the documentation isn't very consistent in the use of definitions.
IsClass is false, as System.Enum inherits from ValueType . You needn't instantiate an enum, like you would do with a 'real' class.
An enumeration is a named constant whose underlying type is any integral type except Char. If no underlying type is explicitly declared, Int32 is used. Programming languages typically provide syntax to declare an enumeration that consists of a set of named constants and their values.
Enum provides methods to compare instances of this class, convert the value of an instance to its string representation, convert the string representation of a number to an instance of this class, and create an instance of a specified enumeration and value.
It's the phrase "provides methods to compare instances of this class" that makes it harder to explain. You don't make (new ) instances of an enum, you assign it's value to a valueType . Alas, the thing that you are assigning is an instance of a valuetype.
See, speech is mainly for communication and not for the errorless movement of ideas. That's why lots of casual talk is misinterpreted, as both sender and receiver use different versions of the definition of the data that is transmitted
Ehr..
..the short answer was that an enumeration is not a class
I are troll
|
|
|
|
|
MSDN also wrote (on the same page you cited):
C#
[SerializableAttribute]
[ComVisibleAttribute(true)]
public abstract <big>class</big> Enum : ValueType, IComparable, IFormattable, IConvertible
When I right-click on Enum in a source window in VS and choose Go To Definition it also indicates it's a class:
using System.Runtime.InteropServices;
namespace System
{
[Serializable]
[ComVisible(true)]
public abstract <big>class</big> Enum : ValueType, IComparable, IFormattable, IConvertible
{
members snipped ...
}
}
The Object Browser in Visual Studio isn't sure what it is. Sometimes it thinks it's a struct and sometimes an abstract class.
The bottom line? I'm still not convinced one way of the other.
|
|
|
|
|