My form has several textboxes and several buttons. The textboxes are loaded with data by the load event. If I make changes to the textboxes and then move the cursor over a button, the textboxes are suddenly loaded again with the original information. I don't click a button. I just move the mouse over one. Why is this happening and how do I stop it?
This cannot happen by itself. I suggest you check all event-settings.
For instance, you could have, by accident, linked the Load event to the Button's OnMouseEnter or something like that.
After your comment:
You should absolutely not use the paint event to initialize things. The paint event will be called after every change in the Form.
So move that code to the Load event.
Related
I've got a TreeList that's basically like a Photoshop layers palette. It's a hierarchical list with checkboxes to toggle visibility of a document's individual layers. This is done via the BeforeChecked event, which is raised right before the .Checked value toggles.
It works fine, except if you double-click it, at which point it all seems to go haywire.
If you double-click a checkbox once, it toggles the checked value twice (which is the intended behavior), but it doesn't toggle the visibility of the layer twice because it doesn't raise the BeforeChecked twice.
I figured I'd get around this by putting this in the MouseDoubleClick event:
TreeViewHitTestInfo hit = treeLayerPalette.HitTest(e.X, e.Y);
hit.Node.Checked = !(hit.Node.Checked);
This works for all double-clicks except for the first one. So it only raises the BeforeChecked event once (and not the MouseDoubleClick) at first, getting the checkbox out of sync with the visibility of the layer, and then all following double-clicks raise both the BeforeChecked and MouseDoubleClick events (which in turn raises the BeforeChecked event), maintaining that incorrect relationship.
Also, at one point, I put a MessageBox.Show() in the DoubleClick event. Awkwardly enough, it does not actually get shown on a double-click, but instead gets shown on a third click, no matter how much time has elapsed between the actual double-click and the third click. A third click performed 20 seconds after a double-click will raise the MouseDoubleClick event, but the actual double-click won't.
What's actually going on here, and how can I fix it?
this is a problem with Checkbox Enabled treeviews, however there are a few acceptable workrounds..
Firstly: MS know about the problem but refuse to fix it... : http://connect.microsoft.com/VisualStudio/feedback/details/775922/treeview-double-click-bug#details <-- The Bug report....
So there is no way but to workaround it.. simplest been to subclass the Treeview and forcibly disable the dblclick on the checkbox...
answer (on SOF) : c# treeview ignore double click only at checkbox
Hope this helps....
When I need to re arrange positions of buttons of controls I use copy/cut and paste but I lose the asociation of the events and need to re assign manually.
Is there a way to do that without losing them?
For example I cut a button and paste it elsewhere.
It had associated the bt_ClickEventFunction, but when pasting it, it loses this.
You can drag them on the Form in order to change their location, you don't need to cur&paste them.
Copy&Paste creates another control with new name and Text while Cut&Paste deletes everything from designer and then regenerates the control as it were but without lines for adding events. I presume that this is because the code for events handlers is in file other that the file created by designer and when you cut the control, event handler doesn't gets deleted from the code since it can be the event handler for some other control also. So when pasting, designer actually only creates the new control as it would when you drag it from the Toolbox but sets the properties from the control hat has been cut.
EDIT Edit based on your comments.
You can do drag&drop even with TabPages. You need to drag it for the small rectangle with arrows like shown on the image:
and you can drag it to the other TabControl, in that case, TabPage will retain all "associated" event handlers.
To restore all the event procedures to their respective controls, go to the VBA code window of the form and then cut, copy and paste the whole module. You may press Ctrl+A, Ctrl+X and Ctrl+V to do so.
This one is a bit tricky to explain.
I have a usercontrol with some textboxes. I also have a menu just above this usercontrol in the same window. Whenever I tab away, the LostFocus fires correctly on the textbox, and this is what I want. Strangely enough, if I click the Menu button on top of my window, the LostFocus event does not fire on the textbox. Is there an elegant way to make sure that my menu properly allows LostFocus to fire on any controls which last had focus?
I also want to avoid having to Update BindingExpressions otherwise I would likely be doing this for N textboxes, which is undesirable.
I can't imagine it is too difficult to achieve this.. I just don't understand how this doesn't work: in most other situations LostFocus always fires.
Any ideas? Thank you.
Is the menu WPF as well or Winforms / UnManaged? If either of the two then the lost focus event does not fire. This can play havoc with WPF controls as many time a save or other data function is being performed from the menu. To counter this I have had to implement multiple ways to combat this. The easiest way was to implement a mouse leave event on the user control itself and perform any actions you require manually in code.
i'm doing a webshop in asp.net (c#).
Is there a way to push the edit button in the gridview through the code of c#?
I have a "new" button, that just adds the row, it would be great if that same row would "open" itself for editing without user having to press "new" then "edit"...
I know there are other ways to do this, i just want to know if this is possible... it would save tons of time!!
thanks in advance for the anwsers!!
Andrej
Just call the event handler you wrote to handle the edit button push.
Basically speaking, all that happens in code when you click a button is that the button's Clicked event is raised. In a GridView, the event is actually something like GridViewButtonClick. However many handlers you have plugged in will then execute (and you can't, and shouldn't have to, control the order of execution). For a built-in button, because you cannot raise the event from outside that button, you can simulate the button click by just calling the handlers you have attached to the event. If this were your own custom control, you could define a method you could call from outside that would cause the control to raise a certain event.
I am creating some textboxes dynamically and I try to get their values when I click a button, but they are gone. I create the text boxes (declaration, initialization, adding them to the place holder) in another click button event. What shall I change to be able to read their values?
If you will create the controls on the Init stage (eg: Init event) on every request (eg, both postback and non-postback) then they will be available and will preserve their state.
There could be several reasons one of Them being your control initialization being executed prior to the event handler. This will be the case if you on post back initialize the controls in page_load. The click event handler is executed after page_load is run
How about getting the values using a simple Request.Form. That should work regardless of how you add the controls. Post some source, so we can see what's going on. :)