KGunder
2011-01-28T12:10:58Z
How can I lock Cells ( which should be displayed only ),
so that they will be skipped if the user navigates
in the grid with the keyboard ( Tab, Enter, Cursor )

I know that I can prevent entering the edit mode
during RequestEdit when I set bCancel=True

Thx

Klaus
Igor/10Tec
2011-01-28T14:25:50Z
Klaus,

iGrid does not provide you with a cell property you can use for that, but you can implement the requested functionality using the mouse and keyboard events of iGrid.

For the mouse, it's very easy. You just analyze whether the user is trying to access the protected cell using the lRow and lCol parameters of the MouseDown event, and if so, set its bDoDefault parameter to False to prevent this cell from selecting.

As for the keyboard, the logic will be more complex. You will need to analyze what cell will be selected in the KeyDown event based on the pressed key (the KeyCode parameter) and then allow the current cell change through the bDoDefault parameter. You will also need to decide whether to "skip" (or jump over) the protected cell or a series of such cells based on the logic of your app.

Can you tell us why do you need this functionality? It would be also nice to see a screenshot of your grid to understand the problem better. Maybe, we'll be able to suggest another solution after looking at your problem closer.
KGunder
2011-01-28T15:18:07Z
Hi Igor,

thank you for your fast response.

Originally Posted by: IgorK@10Tec 


Can you tell us why do you need this functionality?



I am a MS Access Developer and try to replace the Continous Form view
of access, which lacks several features.

I can fill the iGrid with the wonderfull function FillFromRS,
but get stuck with the following function:

- In Access Forms you define a Tab Order for your controls,
so when leaving one field the next field in order gets the focus.
But you may flag a control so that it is excluded from this order
and will not get the focus when cycling through the controls.

e.g. in the following iGrid I will only cycle through
Menge, Gewicht and Chargen. The other fields are for displaying only.
( e.g. Betrag gets calculated by multiplying Menge with Preis )

[img]http://tinypic.com/r/f2tvg3/7[/img]

Best regards

Klaus
Igor/10Tec
2011-01-28T15:42:22Z
If you need to jump only within those 3 columns, then it will be enough easy to implement that using the approach we described above. It would be much harder if you needed to "lock" separate individual cells which are scattered in different places of the grid.

If you have any troubles with implementing the solution, feel free to ask us more.
KGunder
2011-02-02T17:45:03Z
Hi Igor,

so I am trying to implement a behaviour similiar to the MS Access behaviour

MS-Access iGrid Remark
Control_GetFocus CurCellChange cell gets activated
Control_BeforeUpdate BeforeCommitEdit Validating the content of a cell
Control_AfterUpdate AfterCommitEdit Storing the content of the cell
Form_Current ??? This row has now the focus
Form_BeforeUpdate ??? Validating the contents of the row
Form_AfterUpdate ??? Storing the content of the row to the database

For detecting when the user moves to another row I am using the CurCellChange Event
to call my Row_Enter ( = Form_Current ) and Row_Save ( Form_BeforeUpdate + Form_AfterUpdate ) :

Private Sub iGrid_CurCellChange(ByVal lRow As Long, ByVal lCol As Long)
Static lastRow As Long
Static lastCol As Long

If (lRow <> lastRow) Then
' Leaving current Row
If (lastRow <> 0) Then
If (objGrid.RowKey(lastRow) <> -1) Then
If Not Row_Save(lastRow) Then
Call objGrid.SetCurCell(lastRow, objGrid.CurCol) ' Stay in Row
lRow = lastRow: lCol = objGrid.CurCol
End If
End If
End If
Call Row_Enter(lRow)
lastRow = lRow

End If

Call Cell_Enter(lRow, lCol)
lastCol = lCol

End Sub

and I am using the AfterCommitEdit to determine which cell should be
next active cell:

Private Sub iGrid_AfterCommitEdit(ByVal lRow As Long, ByVal lCol As Long)
Dim newValue As Variant

newValue = objGrid.CellValue(lRow, lCol)
Select Case lCol
Case colMenge
Call Menge_Changed(lRow, newValue)
Call objGrid.SetCurCell(lRow, colChargen)
....
End Sub

This works fine with only a little glitch:
When the User edits a cell and leaves the cell pressing the Enter key
Call objGrid.SetCurCell(lRow, colChargen)
will get called but NOT
iGrid_CurCellChange

Leaving the Cell with the Tab key and iGrid_CurCellChange gets triggered
but in the cell after "colChargen"

So why won't the iGrid_CurCellChange get triggered when using SetCurCell
after the user hit Enter ?

Best regards

Klaus

btw: tested with iGrid 4.0 and 4.6
Igor/10Tec
2011-02-03T08:15:21Z
Klaus, two different internal approaches are used to process the TAb and ENTER keys, and that's why you have two different results. The fact is that the TAB key is considered a "serious" system key, and in the most cases its processing is performed first by the development environment that hosts the iGrid ocntrol. To have the ability to process the TAB key in our grid, we had tried many approaches until we found the one based on low-level COM hooks that works acceptably in all main MS development environments - MS Access, MS Word/Excel VBA and VB6. This is the first reason why we do not recommend to go the way like you do.

The other reason to redesign your logic is the following. When the user hits TAB, the current selection is moved to the next cell, but this does not happen on ENTER. This may require two different code snippets to process these situations.

If you wish to dig this more, we can suggest another technique you can try. You can perform the required logic which selects the next cell in the form's Timer event which should be launched once from the AfterCommitEdit event. The construct will look like the following:

Private Sub iGrid0_AfterCommitEdit(ByVal lRow As Long, ByVal lCol As Long)
   TimerInterval = 1
End Sub

Private Sub Form_Timer()
   TimerInterval = 0
   iGrid0.SetCurCell <next_row>, <next_col>
End Sub

The idea is to perform your logic outside of the AfterCommitEdit event which can be raised from different places of the iGrid internals because of the different logic used to process the TAB and ENTER keys.

You may also need to take into account such events as TextEditKeyDown and TextEditKeyPress if you need to process the keys pressed while text editing if you wish to have a special logic for the ENTER key pressed to commit editing. The TextEdit* events are the special events to do that - they were implemented in addition to the KeyDown and KeyPress events of iGrid specially for this situation.
KGunder
2011-02-03T12:18:31Z
Thank You Igor,

it works now like a charm. I am using now the follwing code:


Private Sub iGrid_AfterCommitEdit(ByVal lRow As Long, ByVal lCol As Long)
  Dim newValue As Variant
  
  newValue = objGrid.CellValue(lRow, lCol)
  
  Select Case lCol
    Case colMenge
      Call Menge_Changed(lRow, newValue)
      Call GotoCell(lRow, colChargen)
  ..
End Sub

Private Sub GotoCell(ByVal lRow As Long, ByVal lCol As Long)
  m_GotoRow = lRow
  m_GotoCol = lCol
  TimerInterval = 10
End Sub

Private Sub Form_Timer()
  TimerInterval = 0
  If (m_GotoRow > 0) Then
    objGrid.SetCurCell m_GotoRow, m_GotoCol
    m_GotoRow = 0: m_GotoCol = 0
  End If
End Sub


And to accept when the user clicked with the mouse in another cell I added:


Private Sub iGrid_MouseDown(Button As Integer, Shift As Integer, ByVal x As Single, ByVal y As Single, ByVal lRow As Long, ByVal lCol As Long, ByVal eCellPart As Long, bDoDefault As Boolean)
  Call CancelGoto
End Sub

Private Sub CancelGoto()
  TimerInterval = 0
  m_GotoRow = 0
  m_GotoCol = 0
End Sub


Many Thanks

Klaus
davesyd1970
2011-03-14T09:57:53Z
I have posted an alternative solution which may work (I am checking if there are any errors with it now) under the discussion Prevent click on certain cells 
Igor/10Tec
2011-04-16T05:12:35Z
To you and all customers. Many developers asked us about this functionality, and taking into account all these requests we implemented the CellSelectable property which can be used to implement this task easily. It is already available in a new version of iGrid, v4.7, we released yesterday. Now if you need to prevent a cell from being selected, you just set CellSelectable to False for it.
zahlerj
2011-08-09T22:17:07Z
Igor,

Previously in this topic you stated:

"To have the ability to process the TAB key in our grid, we had tried many approaches until we found the one based on low-level COM hooks that works acceptably in all main MS development environments - MS Access, MS Word/Excel VBA and VB6."

Can you post an example of that code please? I am building an app in Access 2007 and I need to make the Tab key perform in the iGrid OCX control the same way it performs in an Excel spreadsheet.

Thanks,

ZahlerJ
Igor/10Tec
2011-08-10T05:55:06Z
Originally Posted by: zahlerj 

Igor,
Can you post an example of that code please?



Here is a part of it:


Private Sub UserControl_GotFocus()
   ...
   gpOverrideActiveObject m_IPAOHookStruct, Me
   ...
End Sub

Public Sub gpOverrideActiveObject(pIPAOHookStruct As IPAOHookStruct, ByVal pOleObject As IOleObject)
   Dim pOleInPlaceSite             As IOleInPlaceSite
   Dim pOleInPlaceFrame            As IOleInPlaceFrame
   Dim pOleInPlaceUIWindow         As IOleInPlaceUIWindow
   Dim pOleInPlaceActiveObject     As IOleInPlaceActiveObject
   Dim PosRect                     As RECT
   Dim ClipRect                    As RECT
   Dim FrameInfo                   As OLEINPLACEFRAMEINFO
   
   On Error GoTo CleanUpAndExit
   Set pOleInPlaceSite = pOleObject.GetClientSite
   pOleInPlaceSite.GetWindowContext pOleInPlaceFrame, pOleInPlaceUIWindow, VarPtr(PosRect), VarPtr(ClipRect), VarPtr(FrameInfo)
   CopyMemory pOleInPlaceActiveObject, pIPAOHookStruct.ThisPointer, 4
   pOleInPlaceFrame.SetActiveObject pOleInPlaceActiveObject, vbNullString
   If Not pOleInPlaceUIWindow Is Nothing Then
      pOleInPlaceUIWindow.SetActiveObject pOleInPlaceActiveObject, vbNullString
   End If
CleanUpAndExit:
   ' Clear up the inbetween implementation:
   CopyMemory pOleInPlaceActiveObject, 0&, 4
End Sub

And there are some examples and descriptions of this technique in the Internet, for example:

http://www.vbaccelerator.com/home/vb/code/controls/explorer_bar_control/VB5_ExplorerBar_Control_Full_Source_zip_mIOleInPlaceActiveObject_bas.asp 

But to be honest, this won't help you if you wish to apply it to iGrid from "outside". And moreover - it is already in the control!

Can I ask you again, what is the problem? You can read in one of my posts above (skip two posts) that now we have non-selectable cells in iGrid 4.7? Don't they solve your problem?
zahlerj
2011-08-11T17:51:58Z
Igor,

Thanks for the reply.

My problem is slightly different from the one described in this thread. I am making a MS Access form with some typical text boxes, buttons, etc. I also have an iGrid control on the form. The default behavior of the TAB key is to move from control to control within the form. I need to change the behavior of the TAB key when the iGrid control has the focus. When the user presses the tab key, I would like the focus to move to the next cell to the right (as if the right arrow key had been pressed). Similarly, when SHIFT-TAB is pressed, I would like the focus to move to the next cell to the left (as if the left arrow key had been pressed).

My problem isn't with non-selectable cells. I just want to alter the behavior of the TAB key from the MS Access default. I have tried using VBA to call some Windows API's to hook keystrokes, but I get strange results.

That is why your previous post about having solved the problem with low-level COM hooks interested me.

Any info you can provide would be appreciated.

Thanks,
Igor/10Tec
2011-08-15T08:00:35Z
Then we do not understand the problem...

If you place the iGrid control on a brand new MS Access form, and you have other intrinsic Access controls, all works fine - the TAB key moves the current cell selection to the next cell at the right when iGrid has the input focus. At least, that's true for the latest iGrid (4.7).

Can you tell us what version of iGrid, MS Access & Windows you are using? And send us a sample we can launch on our pc to reproduce the problem?

Maybe, something is wrong in your MS Access interface settings (for instance, you can set the behavior for such keys as ENTER)?
zahlerj
2011-08-15T18:37:30Z
Igor,

My version of iGrid is 2.51. I gather that 2.51 version of iGrid does not have the tab functionality as 4.7 does.

Thanks for the info.
Igor/10Tec
2011-08-16T06:45:11Z
Originally Posted by: zahlerj 


My version of iGrid is 2.51. I gather that 2.51 version of iGrid does not have the tab functionality as 4.7 does.



O-h-h yes, this explains all. The TAB key support was introduced in iGrid 3.0 and enhanced later. I'd recommend to upgrade if you need this functionality - after implementing it in iGrid we definitely can say that it is enough hard work, to intercept and make working properly such "system" keys as TAB in MS Access. I guess you already understand 🙂