Click Event not firing if it causes a CellEndEdit Event - c#

I've a DataGridView where I'm showing some results that can be edited by the user, there's a save changes button that will update the database according with anything the user has input. I've checked that if I edit a record, make focus in another component and click the button changes are saved appropiately. Problem is that if I have a cell where the cursor is on, move directly to the save changes button and click it the only event that's fired is the CellEndEdit event, which would register there's a pending change, but it wouldn't update the database, opposite of what would be the expected behaviour, so the user would need to press the button again to do the changes.
Any idea on how to fire first the CellEndEdit and then the Click event in this situation so the result would be the expected one?

I finally got to solve it by checking on the CellEditEnd event if the save changes button is focused or not, if it is, I get to make all the save procedure, I think it should fire both events anyway, but as long as it works I don't care much.
Thanks for your tips, as they helped to guide me.

Related

Don't have Click event in TextBox in WPF C#

I just want to add simple thing, wherever i click on TextBox I want to delete text that is inside. The thing is I DON'T have in list of events, event called Click.. Is this even possible? Or just I need to install some add on. Buttons are fine, they have Click event.
MouseButtonLeftUp would work if you only are concerned with mouse clicks. With that said, what if someone tabs into the box or focus is entered by other means?
At that point you may want to look at the GotFocus event. Any time the TextBox receives focus, you can handle the event.
TextBox has events called MouseLeftButtonUp and MouseLeftButtonDown, you can use them.

Textbox leave event unless tab changes

Using c# winforms vs2008
I'm using a TabControl on a form. Each tab has a different set of input fields. Some of those fields has to be completed. Such as Username. Multiple users will use the same PC, so a the username must remain static. I have a leave event on the require fields which triggers when the textbox loses focus to check if a value was added. In the case of Username, a popup would then presents possible values. That works pretty awesome to ensure accuracy and speed. To problem comes in when the user clicks on another tab, the textbox leave event triggers. How can I prevent the leave_event code from running if the focus changes to a control not on the current Tab?
I have tried different event handlers, but the leave event seem to occur first. I tried textbox validating event handler, but also no success. I tried adding a If-statement in front of the code to check the tab number, or tabcontrol state - no joy - as before anything else changes, the leave event fires.
The only remaining thing I can think of is to loop through all the controls on the tab to check if they have focus, but that just feels messy.
Any other suggestions?
I have found a partial solution. Using a Mouse_Enter and _Leave event on the tab, I set a flag to determine whether the mouse was clicked in the form or outside. If the flag is set to false, the leave event dont run. This will not solve short cut key presses though. But that I can handle later.

TextChange in Gridview Textbox prevent button event

I have a text box on a Gridview which I'm allowing some data to be edited. When the enter key is hit, the TextChanged event happens, like I'd expect. But when i change the data and click a button, the button effect not happen. I must click the button again to fire button event. I think it happen because the grid didnot lost it focus.
How to make it possible fire the button event just in one click?
You can change your gridview element's IsTabStop property to false to gain that effect.
Also if you want to cycle with Tab you can TabNavigation="Cycle" .
Both changes are in xaml.
Not much we can do to help you here without the code itself but here are couple things you could try to debug this:
Try different browsers – it may be a browser issue
Try some client side debugging – just open console and see if anything happens when you click the button for the first time

SelectedIndexChanges fires before TextChanged event

I have a grid which contains multiple columns/rows with ASP TextBox controls. In addition to this, above the grid I have a radio button list which contains years.
The user can enter numbers into the TextBoxes and then click an item on the RadioButton list to save the information then switch years or click an update button to just save the information and remain viewing the data.
If I click the 'save' button the textchanged event handler fires and I know what rows on my grid had something changed, then I update my DB and then get the data again to display to the user.
If however I click the radiobuttonlist to switch years the SelectedIndexChanged event fires but the TextChanged event handler does not run because the save and get data runs first, rebinding the grid and eventhandler.
This appears to me to be something to do with the way events run in .net, does anyone know how can I get the textchanged event handler to run first when clicking a radio button list?
I'm using VS2005, .Net 2.5, ASP.Net, C#
Thanks in advance
Your question is not clear. Anyway i can understand that you have problem with the event handlers and how they are called.
I want to know what is the need of calling the textchanged event and SelectedIndexChanged. Even they are not called your data would be get saved perfectly.

C# Datagridview SelectionChanged Event fires earlier than I want it to

I'm working with Windows forms. I want an event to fire when the user makes a selection of cells (or one cell) in the datagridview. The SelectionChanged Event is firing as soon as I select one cell. Is there any way to have it wait for the user to be done selecting?
I have tried the CellMouseUp event, but I don't like its behaviour because if MouseUp happens outside the grid it doesn't fire.
As they select each cell a new selection change should be fired. so you are looking at "remembering" the selected cells each time the eventhandler gets triggered and then doing your processing based on that.
How much of a pain this going to be depends on what processing you are doing with the selection. Could be a good deal.

Categories

Resources