I have a textbox and a grid displaying 10 lines of item.
First, I modified data in grid.
Then while editing the second line of data, I found clicking out of the grid will not set the focus out from the grid.
Why and How can I set the grid out from edit mode when I click out of the grid?
Please advice, Thanks.
Hi Mithun,
The issue you are describing is incredibly complex and there are dozens of different factors that might be having an effect, so it's really hard to even discuss it in a forum post.
Focus has a lot of different meanings. There's Keyboard focus, there's the active control, and then there is a the accessibility focus.
When you enter a cell of the grid, what control has focus? It depends on the cell and what kind of editor it's using. Your basic text cell shows a TextBox over the cell when it goes into edit mode. So the TextBox control gets the focus. But the grid contains the TextBox and therefore the grid contains the focus, even though it doesn't directly have focus. A masked cell doesn't use a TextBox, so when a masked cell is in edit mode, the grid itself has focus. But I am referring here to keyboard focus, not accessibility - and they are not the same thing.
As far as accessibility goes, it depends what version of the controls you are using, what version of Windows you are using, and what accessibility client you are using. The accessibility in the Infragistics Windforms controls was added a long time ago and so it uses the old MSAA accessibility model. A lot of the newer accessibility clients are using the new UIA model, so they don't work quite as well with the older controls.
When a cell enters edit mode is the focus on the grid or on the cell ?
I have an issue with a grid, when i tab between the cells and enter a cell in the grid in edit mode, the focus is on the editable cell but when i use a screen reader it reads the entire grid instead of just the the cell which is in edit mode. But when i tab into a cell which is having a dropdownbox as control in cell the screen reader works perfectly reading just that cell. Can you please help me understand whats wrong here. As per my belief when the cell enters edit mode the whole grid gets the focus instead of just that cell. Is that how it works ?
Hi,
Okay, I understand now. As a general rule, you should not use the GotFocus and LostFocus events in DotNet, because these events reflect actual window messages and don't account for child controls. You should use the Enter and Leave events instead.
What's happening here is that when you enter edit mode on a grid cell, the cell displays a child control inside / over the cell to allow the user to edit. So it is this child control (TextBox) that is taking focus and thus the grid loses focus.
Thanks for the reply.
I figured the ESC button after posting, so I am going with that.
Regarding the LoseFocus method... This was the code I added from the example provided in the first response (3247.WindowsFormsApplication3.rar)
It seems to work the opposite of what I expected.
This is the details of the sequence.
1) User enters a value in a text box (above the grid in the window).
2) Data is retrieved from the database and populates the field.
Some fields in the grid are set as non-editable (display only).
3) User clicks on an editable field.
Control goes to the LoseFocus method.
Why? I just clicked into the cell on the grid.. so I just set focus on it, so why does it go to LoseFocus.
If you cancel BeforeExitEditMode, then the user cannot click a button, because clicking a button requires the button to take focus and you are preventing the button from taking focus.
What the user can do in a case like this is press Esc to cancel the pending changes in the current cell. Pressing Esc again will cancel any changes in the entire active row.
Another option would be to use a button that does not take focus, such as a toolbar button.
A D said: When I added your code, and then click in a cell when the form displays, the LoseFocus method is being invoked. Any ideas as to the causes of these two issues would be appreciated).
When I added your code, and then click in a cell when the form displays, the LoseFocus method is being invoked.
Any ideas as to the causes of these two issues would be appreciated).
I'm afraid I don't understand. Why is this a problem and how is it any different than the first problem?