473,289 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

DataGrid Tabbing

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


Mar 18 '07 #1
6 2206
Not sure how you are putting the combobox in your datagrid, but try
this if possible. Derive the ComboBox class you are using, override
its WndProc method and ignore the keyup. This is how the first VB
sample link in this FAQ entry avoid the same problem you are
describing. Without this code, as you tab through the grid, on keydown
your tab into the combobox cell, and on keyup you tab out of the
cell.

http://www.syncfusion.com/faq/window...earch/480.aspx
Public Class NoKeyUpCombo
Inherits ComboBox
Private WM_KEYUP As Integer = &H101
Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
If m.Msg = WM_KEYUP Then
'ignore keyup to avoid problem with tabbing &
dropdownlist;
Return
End If
MyBase.WndProc(m)
End Sub 'WndProc
End Class 'NoKeyUpCombo

================
Clay Burch
Syncfusion, Inc.

Mar 18 '07 #2
Hi Thanks Clay,

I am, as you suggested deriving the ComboBox and consuming the KeyUp and if
I Tab through the DataGrid without any code to Tab through the Hidden and
Read Only Cells it Tabs correctly into the Combo Box.

With the code to Tab past the Hidden and Read Only Cells, which works
perfectly on Text Box Cells, it Tabs in and then out again.

If I put a MsgBox in the code or even if I step through the code it works
perfectly but when I let it run unabated it tabs in and out again.

Doug
"ClayB" <cl***@syncfusion.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
Not sure how you are putting the combobox in your datagrid, but try
this if possible. Derive the ComboBox class you are using, override
its WndProc method and ignore the keyup. This is how the first VB
sample link in this FAQ entry avoid the same problem you are
describing. Without this code, as you tab through the grid, on keydown
your tab into the combobox cell, and on keyup you tab out of the
cell.

http://www.syncfusion.com/faq/window...earch/480.aspx
>

Public Class NoKeyUpCombo
Inherits ComboBox
Private WM_KEYUP As Integer = &H101
Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
If m.Msg = WM_KEYUP Then
'ignore keyup to avoid problem with tabbing &
dropdownlist;
Return
End If
MyBase.WndProc(m)
End Sub 'WndProc
End Class 'NoKeyUpCombo

================
Clay Burch
Syncfusion, Inc.

Mar 18 '07 #3
Here is a sample that skips hidden columns around a combobox problem
without this problem.

http://www.syncfusion.com/Support/us...o_9c97c963.zip

=====================
Clay Burch
Syncfusion, Inc.
Mar 18 '07 #4
Thanks Clay,
Your sample works very well.
I used your sample sub
Sub dataGrid1_CurrentCellChanged

in my project and was still seeing the same problem.

I will look into my DataGridCombo code and ite inheritance.

Again Thanks
Doug
"ClayB" <cl***@syncfusion.comwrote in message
news:11**********************@e1g2000hsg.googlegro ups.com...
Here is a sample that skips hidden columns around a combobox problem
without this problem.

http://www.syncfusion.com/Support/us...o_9c97c963.zip
>
=====================
Clay Burch
Syncfusion, Inc.


Mar 18 '07 #5
Clay,
I think I may have found where the problem is coming from.
My ComboBoxes ComboBoxStyle = DropDown not DropDownList.

When I changed your Style to DropDown I saw the problem on your Sample as
well.

I need to have them as dropdown so that the User can type the value into the
combo to select the value.
Actually they will be Locations so
2BMovd;A01;A02;A03;AFloor;A04; B01;B02 etc

They don't want to select with the mouse or type "A" repeatedly to cylce
through all the "A" locations. So I had to set up the Combo as a DropDown
and then the Tabbing problem occurs.

If you have any suggestions to resolve it while keeping the DropDown Style I
would really appreciate it.

"ClayB" <cl***@syncfusion.comwrote in message
news:11**********************@e1g2000hsg.googlegro ups.com...
Here is a sample that skips hidden columns around a combobox problem
without this problem.

http://www.syncfusion.com/Support/us...o_9c97c963.zip
>
=====================
Clay Burch
Syncfusion, Inc.


Mar 19 '07 #6
I was able to get the sample working by using PreProcessMessage to
ignore the KEYUP instead of WndProc.

Public Overrides Function PreProcessMessage(ByRef msg As
System.Windows.Forms.Message) As Boolean
If msg.Msg = WM_KEYUP Then
Return True
End If
Return MyBase.PreProcessMessage(msg)
End Function

===================
Clay Burch
Syncfusion, Inc.

Mar 19 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Faith | last post by:
I found code on www.codeproject.com. Here is a sample it is called DataGridColumnDropDown. I modified it to use the text box when I wanted it to depended on a certain search criteria. Public...
2
by: PAUL GROSSMAN | last post by:
Hello everyone. I am working with a DataGrid using VB .Net (Windows Forms). I want to make one of the columns un-editable. I was able to do that by setting the ...
3
by: Dav | last post by:
I have a Winform with a derived datagrid and a button that adds a row to the datagrid in its Click event. The button has a shortcut text "&New Row". When I enter a value in a datagrid cell and...
4
by: jibran | last post by:
Hello. I have wrapped the DataGrid control with my own class (SmartDataGrid) adding some necessary functionality. My current webform has 2 SmartDataGrids. The first is populated by selected...
13
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value....
4
by: Melson | last post by:
Hi I've a problem. Can anyone help. I would like to use datagrid for data entry. How can I set the number of rows in the datagrid. And use the datagrid to update the ms sql table. regards...
0
by: Nick | last post by:
Hi, This is a very common issue. I have a read only Windows Application datagrid, on which i want to prevent the tabbing between the columns and rows. What needs to happen is this: When i...
0
by: Nick | last post by:
Hi, I have a requirement to build a mouse free windows application and have to hence rely heavily on the tabbing indices. However, I'm facing some issues when the tab goes to a datagrid. It...
10
by: Doug Bell | last post by:
Hi I am still having problems with Tabbing through a DataGrid with a DataGridComboBox Column. I need to allow the User to Type the value into the ComboBox so consequently its ComboBoxStyle is...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.