We are running into a strange problem with WinGrid. If a new Form is opened with in grid's BeforeExitEditMode event handler then instead of displaying the form it gets minimized to task bar. Here is an example code- an ultragrid is place in Form1
f.Show()
End Sub
We do not want to open Form2 as dialog form. Is this a bug in grid or there is any correct way of writing code?
thanks in advance,
Abhishek
I'm guessing here, but it's possible that since you're doing this in the BeforeExitEditMode event, there are focus-related issues coming into play here, and the grid/editor may be trying to maintain focus at this point. What are you trying to do in this event? It would seem to me that you would need to have a modal dialog if this new form is going to handle logic related to whether or not to exit edit mode.
-Matt
Hi Matt,
Thanks for the reply. We are testing weather value entered by user exist in database if we not we pop up a master form so that user can enter master data. We want to validate that only valid data is entered by user before leaving the cell.
We tried opening master form in both normal and dialog mode. Unfortunately focus is not set on first control of that master form; focus still remains on that active cell. One can change focus manually though. It seems like this is a bug in WinGrid. We donot want to open our form in dialog mode due to some technical constraints.
Abhishek,
I just tried this out and I don't have the problem with the new form minimizing to the taskbar. I'm not sure that this would be a bug though, since what's likely happening is that you're showing a new form in the BeforeExitEditMode, which will then take focus. Since the grid hasn't fully processed the action that caused the grid to exit edit mode, at this point it will complete the process (i.e. set focus to a new cell and enter edit mode); since the logic has already been performed to focus your new form, the grid will now focus itself and the relevant cell. Basically, the steps seem to be:
1) Press Tab key (as an example)
2) BeforeExitEditMode fires, new form is shown and given focus
3) AfterExitEditMode and BeforeCellActivate/BeforeEnterEditMode fire
4) Grid sets focus to new cell, and itself, due to the Tab key action
You might be able to keep a flag indicating that you've shown a new form so that you can cancel the BeforeCellActivate or BeforeEnterEditMode events.
Thanks for replies. We have corrected the problem of form minimizing to task bar. However main problem still remains: the opened form did not gets focus. Focus still remains in the cell of the grid. We need to validate the data in the cell 9against values in database). If user entered record does not exist as master form is popped up to enter the record. We need to set e.Cancel=True in BeforeExitEditMode so that focus does not move out of cell unless value in cell is validated.
Logic is something like this
grid_BeforeExitEditMode(sender as object, e as Infragistics.Win.UltraWinGrid.BeforeExitEditModeEventArgs)
If ValidateRecord(e.ActiveCell.Text)=False then
'do not allow to move focus out of cell
e.Cancel= True
'show relevant master form for data entry
dim f as new MasterForm
f.show
'problem is here form gets shown but does not receives focus '(You can change focus with help of mouse though). So if user presses TAB key at 'this point BeforeExitEditMode fires again and a new instance of MasterForm is shown.
'Contrary to this similar logic written in TextBoxes validating event works fine
End if
This could be a timing issue as well, and may be caused by the grid trying to set focus back to itself and the cell that is in edit mode. One thing that you could try is to use a BeginInvoke call to show the form so that it occurs a little later, possibly after the grid has done its processing.