Home - Forums-.NET - FlyGrid.Net (Windows Forms) - how to use grid_LostFocus ?

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

how to use grid_LostFocus ?
Link Posted: 11-Sep-2005 21:23
Hi,
I'm doing this:

Private Sub dgDetail_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgDetail.LostFocus
        If Not dgDetail.Focus Then
          'do stuff
        end if
end sub


but whatever I type in the grid, this event is called continually, stoping me from entering data in my grid (as if it was not multi-threaded, actually is it?)
What should I do to check if the grid lost the focus but in the meantime still being able to enter data in the grid ?

Regards
Link Posted: 12-Sep-2005 06:01
You should check ContainsFocus property - probably some of the FlyGrid child controls (inplace editor, dropdown list etc) receives focus.
Link Posted: 12-Sep-2005 07:39
Are you sure about this ContainsFocus property ?
I can't find it, and it's not documented in the help file either.

Can you help further please ?

Regards
Link Posted: 12-Sep-2005 07:48
This property is documented as Control.ContainsFocus
Link Posted: 13-Sep-2005 01:51
Yes I've found it. Here is what I do now:

Private Sub dgDetail_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgDetail.LostFocus
        If Not dgDetail.ContainsFocus Then
            If Not SaveRow(dgDetail, dgDetail.Selected, CheckSameRow:=False) Then
                dgDetail.Focus()
                SelectRowInGrid(dgDetail, m_SelectedCtrl)
            End If
        End If
End Sub

When my grid loses the focus I try to save data and if it fails I give the focus back to my grid using dgDetail.Focus() and then I reselect the correct row.

However after giving the focus back to my grid it goes back into the save function, which means dgDetail.ContainsFocus is False whereas it should be True. Do you know what might explain this?
Regards
Link Posted: 13-Sep-2005 05:49
Probably FlyGrid not yet processed reception of focus, modify your method, as following:
'field indicating that dgDetail in process of receiving focus
Private Boolean inFocusing = false
' LostFocus handler
Private Sub dgDetail_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgDetail.LostFocus
  If (Not dgDetail.ContainsFocus) And (Not inFocusing) Then
    If Not SaveRow(dgDetail, dgDetail.Selected, CheckSameRow:=False) Then
      inFocusing = True 'enter into receiving focus
      Try
        dgDetail.Focus()
        SelectRowInGrid(dgDetail, m_SelectedCtrl)
      Finally
        inFocusing = False ' exit from receiving focus
      End Finally
    End If    
  End If
End Sub
Link Posted: 20-Oct-2011 01:46
it is not able to recognize saverow and selectrowingrid method????