D
Doug Bell
Hi
I have a DataGrid with some hidden columns and also some read Only and some
ComboBox Columns.
Sandard Tabbing through the Datagrid sees the focus go to the hidden columns
requiring further Tabbing to get to the desired column but it works fine
stopping correctly on the ComboBox column.
I have built a routine to test whether the use is Tabbing forward or back
(Shift Tab) by looking at the last location, not by trapping the Keys. If
tabbing (say forward) and it lands on a hidden (zero width) column or a Read
Only column, it sets the location explicitly to the next column and the
DataGrids CurrentCellChanged event fires to see if it needs to move further.
This works fine except when it gets to a ComboBox Column and there it opens
the ComboBox (correctly) but then moves on to the bext column (hidden) and
then on to the next column another Combo Box Column and stops.
Like wise if tabbing back it doesn't stop at the first Comb on the way back.
The code looks fine, I just can't see what is causing this behavior except I
found if I put a MsgBox in the code to halt it after it moves then it works
fine.
Also found that the code does not seem to flow as written. It steps through
correctly but when I use a series of Console.Writelines it looks a bit
strange.
Can anyone shed some light on this for me or suggest anything?
Here is my Tabbing code and the result of the Writelines:
______________________________________________________
Private iPrevCol As Integer
Private iPrevRow As Integer
____________________________________________________________
Private Sub GrdODs_CurrentCellChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles GrdODs.CurrentCellChanged
Console.WriteLine("Cell Changed -Previous Row/Col: " & iPrevRow & "/" &
iPrevCol)
TabThruGrid()
End Sub
____________________________________________
Private Sub TabThruGrid()
Dim dg As DataGrid = GrdODs
Dim cellItm As DataGridCell = dg.CurrentCell
Dim iCurrentRow As Integer = cellItm.RowNumber
Dim iCurrentCol As Integer = cellItm.ColumnNumber
Dim iLastRow, iLastCol As Integer
Dim fKeepTabbing As Boolean
Dim stTableName As String = dtOrdDetails.TableName.ToString
Dim iMove As Int16
Try
'fKeepTabbing = dg.TableStyles(stTableName). _
' GridColumnStyles(iCurrentColumn).Width = 0 Or _
' dg.TableStyles(stTableName). _
' GridColumnStyles(iCurrentColumn).ReadOnly()
'If fKeepTabbing Then
For iLastCol = _
dg.TableStyles(stTableName).GridColumnStyles.Count - 1 _
To 0 Step -1
'Find last visible Col
If dg.TableStyles(stTableName). _
GridColumnStyles(iLastCol).Width > 0 And _
Not dg.TableStyles(stTableName). _
GridColumnStyles(iLastCol).ReadOnly() Then
Exit For
End If
Next iLastCol
If iLastCol = 0 Then
Exit Sub
End If
iLastRow = dtOrdDetails.Rows.Count - 1
If (iCurrentCol > iPrevCol And iCurrentRow = iPrevRow) Or _
(iCurrentCol = 0 And iPrevCol = iLastCol And _
iCurrentRow = iPrevRow) Or _
(iCurrentCol = iLastCol And iCurrentRow > iPrevRow) Or _
(iCurrentCol = iLastCol And iPrevRow = iLastRow) Then
'Tab forward
iMove = 1
ElseIf (iCurrentCol < iPrevCol And iCurrentRow = iPrevRow) Or _
(iCurrentCol = 0 And iCurrentRow < iPrevRow) Or _
(iCurrentCol = 0 And iCurrentRow = 0 And _
iCurrentCol <> iPrevCol And iCurrentRow <> iPrevRow) Then
'Tab back
iMove = -1
Else
iMove = 0
End If
Console.WriteLine("Current Position (R/C)=" & iCurrentRow & "/" &
iCurrentCol)
If iMove = 1 Then 'If Tabbing forward
Console.WriteLine("Tab was forward")
If iCurrentCol = iLastCol Then 'If at last visible Col
Console.WriteLine("Col = Last Col")
If iCurrentRow = iLastRow Then 'If at last Row
Console.WriteLine("Row = LastRow")
'Move to first Col and first Row
fKeepTabbing = dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).Width = 0 Or _
dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).ReadOnly()
If fKeepTabbing Then
Console.WriteLine("Keep Tabbing, hidden Col or Read Only")
Console.WriteLine("Move to 0/0")
dg.CurrentCell = New DataGridCell(0, 0)
ButtonSave.Focus()
Console.WriteLine("Moved: 0 / 0")
End If 'fKeepTabbing
Else 'intCurrentRow = intLastRow
Console.WriteLine("Not at Last Row")
'Not at last Row so move to next Row and to Col 0
fKeepTabbing = dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).Width = 0 Or _
dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).ReadOnly()
If fKeepTabbing Then
Console.WriteLine("Keep Tabbing, hidden Col or Read Only")
Console.WriteLine("Move to " & iCurrentRow + 1 & "/0")
dg.CurrentCell = _
New DataGridCell(iCurrentRow + 1, 0)
Console.WriteLine("Moved: iCurrentRow - 1 / 0")
End If 'fKeepTabbing
End If 'intCurrentRow = intLastRow
Else 'intCurrentRow = intLastRow
'Not at last Col
'So move to next Col
Console.WriteLine("Not at Last Col")
fKeepTabbing = dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).Width = 0 Or _
dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).ReadOnly()
If fKeepTabbing Then
Console.WriteLine("Keep Tabbing, hidden Col or Read Only")
Console.WriteLine("move to " & iCurrentRow & "/" & iCurrentCol + 1)
dg.CurrentCell = _
New DataGridCell(iCurrentRow, iCurrentCol + iMove)
Console.WriteLine("Moved: iCurrentRow - 1 / iLastColumn")
End If 'Not fKeepTabbing
End If 'intCurrentRow = intLastRow
ElseIf iMove = -1 Then 'If Tabbing back
Console.WriteLine("Move was backward")
If iCurrentCol = 0 Then 'If at 1st Col
Console.WriteLine("At 1st Col")
If iCurrentRow = 0 Then 'If at 1st Row
Console.WriteLine("At 1st Row")
'Move to Last Row
fKeepTabbing = dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).Width = 0 Or _
dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).ReadOnly()
If fKeepTabbing Then
Console.WriteLine("Keep Tabbing, hidden Col or Read Only")
Console.WriteLine("move to " & iLastRow & "/" & iLastCol)
dg.CurrentCell = _
New DataGridCell(iLastRow, iLastCol)
Console.WriteLine("Moved: iLastRow / iLastColumn")
End If 'fKeepTabbing
Else 'intCurrentRow = 0
'Not at 1st Row
Console.WriteLine("Not at 1st Row")
'Move back 1 Row to the last Col
fKeepTabbing = dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).Width = 0 Or _
dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).ReadOnly()
If fKeepTabbing Then
Console.WriteLine("Keep Tabbing, hidden Col or Read Only")
Console.WriteLine("move to " & iCurrentRow - 1 & "/" & iCurrentCol)
dg.CurrentCell = _
New DataGridCell(iCurrentRow - 1, iCurrentCol)
Console.WriteLine("Moved: iCurrentRow - 1 / iLastColumn")
End If 'fKeepTabbing
End If 'intCurrentRow = 0
Else 'intCurrentColumn = 0
Console.WriteLine("Not at 1st Col")
'Not at 1stCol
fKeepTabbing = dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).Width = 0 Or _
dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).ReadOnly()
If fKeepTabbing Then
Console.WriteLine("Keep Tabbing, hidden Col or Read Only")
Console.WriteLine("Move to " & iCurrentRow & "/" & iCurrentCol + iMove)
dg.CurrentCell = _
New DataGridCell(iCurrentRow, iCurrentCol + iMove)
Console.WriteLine("Moved: iCurrentRow / iCurrentColumn + (iMove):" & iMove)
End If 'fKeepTabbing
End If 'intCurrentColumn = 0
End If 'If iMove = 1 ie If tabbing
'Else 'fKeepTabbing
'Console.WriteLine("-Col:" & iCurrentColumn & " -" & Now & ": -Return ")
'dacSetFormCntls()
'End If 'fKeepTabbing ie If Cell Hidden
TextBoxCol.Text = iPrevRow & "; " & iPrevCol
Catch
dg.CurrentCell = New DataGridCell(0, 0)
Console.WriteLine("Error: -Col:" & iCurrentCol & " -" & Now)
Console.WriteLine(" Move to 0/0")
End Try
' Set Previous Row and Col
cellItm = dg.CurrentCell
iPrevRow = cellItm.RowNumber
iPrevCol = cellItm.ColumnNumber
Console.WriteLine("Prev Row/Col =" & iPrevRow & "/" & iPrevCol)
End Sub
I have a DataGrid with some hidden columns and also some read Only and some
ComboBox Columns.
Sandard Tabbing through the Datagrid sees the focus go to the hidden columns
requiring further Tabbing to get to the desired column but it works fine
stopping correctly on the ComboBox column.
I have built a routine to test whether the use is Tabbing forward or back
(Shift Tab) by looking at the last location, not by trapping the Keys. If
tabbing (say forward) and it lands on a hidden (zero width) column or a Read
Only column, it sets the location explicitly to the next column and the
DataGrids CurrentCellChanged event fires to see if it needs to move further.
This works fine except when it gets to a ComboBox Column and there it opens
the ComboBox (correctly) but then moves on to the bext column (hidden) and
then on to the next column another Combo Box Column and stops.
Like wise if tabbing back it doesn't stop at the first Comb on the way back.
The code looks fine, I just can't see what is causing this behavior except I
found if I put a MsgBox in the code to halt it after it moves then it works
fine.
Also found that the code does not seem to flow as written. It steps through
correctly but when I use a series of Console.Writelines it looks a bit
strange.
Can anyone shed some light on this for me or suggest anything?
Here is my Tabbing code and the result of the Writelines:
______________________________________________________
Private iPrevCol As Integer
Private iPrevRow As Integer
____________________________________________________________
Private Sub GrdODs_CurrentCellChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles GrdODs.CurrentCellChanged
Console.WriteLine("Cell Changed -Previous Row/Col: " & iPrevRow & "/" &
iPrevCol)
TabThruGrid()
End Sub
____________________________________________
Private Sub TabThruGrid()
Dim dg As DataGrid = GrdODs
Dim cellItm As DataGridCell = dg.CurrentCell
Dim iCurrentRow As Integer = cellItm.RowNumber
Dim iCurrentCol As Integer = cellItm.ColumnNumber
Dim iLastRow, iLastCol As Integer
Dim fKeepTabbing As Boolean
Dim stTableName As String = dtOrdDetails.TableName.ToString
Dim iMove As Int16
Try
'fKeepTabbing = dg.TableStyles(stTableName). _
' GridColumnStyles(iCurrentColumn).Width = 0 Or _
' dg.TableStyles(stTableName). _
' GridColumnStyles(iCurrentColumn).ReadOnly()
'If fKeepTabbing Then
For iLastCol = _
dg.TableStyles(stTableName).GridColumnStyles.Count - 1 _
To 0 Step -1
'Find last visible Col
If dg.TableStyles(stTableName). _
GridColumnStyles(iLastCol).Width > 0 And _
Not dg.TableStyles(stTableName). _
GridColumnStyles(iLastCol).ReadOnly() Then
Exit For
End If
Next iLastCol
If iLastCol = 0 Then
Exit Sub
End If
iLastRow = dtOrdDetails.Rows.Count - 1
If (iCurrentCol > iPrevCol And iCurrentRow = iPrevRow) Or _
(iCurrentCol = 0 And iPrevCol = iLastCol And _
iCurrentRow = iPrevRow) Or _
(iCurrentCol = iLastCol And iCurrentRow > iPrevRow) Or _
(iCurrentCol = iLastCol And iPrevRow = iLastRow) Then
'Tab forward
iMove = 1
ElseIf (iCurrentCol < iPrevCol And iCurrentRow = iPrevRow) Or _
(iCurrentCol = 0 And iCurrentRow < iPrevRow) Or _
(iCurrentCol = 0 And iCurrentRow = 0 And _
iCurrentCol <> iPrevCol And iCurrentRow <> iPrevRow) Then
'Tab back
iMove = -1
Else
iMove = 0
End If
Console.WriteLine("Current Position (R/C)=" & iCurrentRow & "/" &
iCurrentCol)
If iMove = 1 Then 'If Tabbing forward
Console.WriteLine("Tab was forward")
If iCurrentCol = iLastCol Then 'If at last visible Col
Console.WriteLine("Col = Last Col")
If iCurrentRow = iLastRow Then 'If at last Row
Console.WriteLine("Row = LastRow")
'Move to first Col and first Row
fKeepTabbing = dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).Width = 0 Or _
dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).ReadOnly()
If fKeepTabbing Then
Console.WriteLine("Keep Tabbing, hidden Col or Read Only")
Console.WriteLine("Move to 0/0")
dg.CurrentCell = New DataGridCell(0, 0)
ButtonSave.Focus()
Console.WriteLine("Moved: 0 / 0")
End If 'fKeepTabbing
Else 'intCurrentRow = intLastRow
Console.WriteLine("Not at Last Row")
'Not at last Row so move to next Row and to Col 0
fKeepTabbing = dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).Width = 0 Or _
dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).ReadOnly()
If fKeepTabbing Then
Console.WriteLine("Keep Tabbing, hidden Col or Read Only")
Console.WriteLine("Move to " & iCurrentRow + 1 & "/0")
dg.CurrentCell = _
New DataGridCell(iCurrentRow + 1, 0)
Console.WriteLine("Moved: iCurrentRow - 1 / 0")
End If 'fKeepTabbing
End If 'intCurrentRow = intLastRow
Else 'intCurrentRow = intLastRow
'Not at last Col
'So move to next Col
Console.WriteLine("Not at Last Col")
fKeepTabbing = dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).Width = 0 Or _
dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).ReadOnly()
If fKeepTabbing Then
Console.WriteLine("Keep Tabbing, hidden Col or Read Only")
Console.WriteLine("move to " & iCurrentRow & "/" & iCurrentCol + 1)
dg.CurrentCell = _
New DataGridCell(iCurrentRow, iCurrentCol + iMove)
Console.WriteLine("Moved: iCurrentRow - 1 / iLastColumn")
End If 'Not fKeepTabbing
End If 'intCurrentRow = intLastRow
ElseIf iMove = -1 Then 'If Tabbing back
Console.WriteLine("Move was backward")
If iCurrentCol = 0 Then 'If at 1st Col
Console.WriteLine("At 1st Col")
If iCurrentRow = 0 Then 'If at 1st Row
Console.WriteLine("At 1st Row")
'Move to Last Row
fKeepTabbing = dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).Width = 0 Or _
dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).ReadOnly()
If fKeepTabbing Then
Console.WriteLine("Keep Tabbing, hidden Col or Read Only")
Console.WriteLine("move to " & iLastRow & "/" & iLastCol)
dg.CurrentCell = _
New DataGridCell(iLastRow, iLastCol)
Console.WriteLine("Moved: iLastRow / iLastColumn")
End If 'fKeepTabbing
Else 'intCurrentRow = 0
'Not at 1st Row
Console.WriteLine("Not at 1st Row")
'Move back 1 Row to the last Col
fKeepTabbing = dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).Width = 0 Or _
dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).ReadOnly()
If fKeepTabbing Then
Console.WriteLine("Keep Tabbing, hidden Col or Read Only")
Console.WriteLine("move to " & iCurrentRow - 1 & "/" & iCurrentCol)
dg.CurrentCell = _
New DataGridCell(iCurrentRow - 1, iCurrentCol)
Console.WriteLine("Moved: iCurrentRow - 1 / iLastColumn")
End If 'fKeepTabbing
End If 'intCurrentRow = 0
Else 'intCurrentColumn = 0
Console.WriteLine("Not at 1st Col")
'Not at 1stCol
fKeepTabbing = dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).Width = 0 Or _
dg.TableStyles(stTableName). _
GridColumnStyles(iCurrentCol).ReadOnly()
If fKeepTabbing Then
Console.WriteLine("Keep Tabbing, hidden Col or Read Only")
Console.WriteLine("Move to " & iCurrentRow & "/" & iCurrentCol + iMove)
dg.CurrentCell = _
New DataGridCell(iCurrentRow, iCurrentCol + iMove)
Console.WriteLine("Moved: iCurrentRow / iCurrentColumn + (iMove):" & iMove)
End If 'fKeepTabbing
End If 'intCurrentColumn = 0
End If 'If iMove = 1 ie If tabbing
'Else 'fKeepTabbing
'Console.WriteLine("-Col:" & iCurrentColumn & " -" & Now & ": -Return ")
'dacSetFormCntls()
'End If 'fKeepTabbing ie If Cell Hidden
TextBoxCol.Text = iPrevRow & "; " & iPrevCol
Catch
dg.CurrentCell = New DataGridCell(0, 0)
Console.WriteLine("Error: -Col:" & iCurrentCol & " -" & Now)
Console.WriteLine(" Move to 0/0")
End Try
' Set Previous Row and Col
cellItm = dg.CurrentCell
iPrevRow = cellItm.RowNumber
iPrevCol = cellItm.ColumnNumber
Console.WriteLine("Prev Row/Col =" & iPrevRow & "/" & iPrevCol)
End Sub