|
|
|
It happens quite often that you have a DataGrid with hidden columns (with width = 0), because you need their values but don't want to show them to the user. However, when you tab through the DataGrid's columns, these "hidden" columns are still taken into account in the tab order. This means that when the user presses the Tab key the focus might seem to disappear from the DataGrid and the form, when in reality it is on the hidden cell. This behavior is not very user friendly, and may leave the user wondering what happened, and if he has to click somewhere or press Tab again. It would be much better if the Tab could skip some columns, so that everything work as if those hidden columns were not there at all. This skipping mechanism could also be useful in other situations, when you have visible columns but don't want the user to be able to give them the focus, either by pressing Tab or by clicking directly on them. You can solve this problem by handling the DataGrid's CurrentCellChanged event, and simulate a Tab keypress when the user selects an "inaccessible" column. Here's the code to enable/disable the column-skipping mechanism: |
Click here to copy the following block |
Sub EnableDataGridColumnSkip(ByVal grid As DataGrid, _ ByVal ParamArray columnsToSkip() As Integer) grid.Tag = columnsToSkip AddHandler grid.CurrentCellChanged, AddressOf GenDataGrid_CurrentCellChanged End Sub
Sub DisableDataGridColumnSkip(ByVal grid As DataGrid) RemoveHandler grid.CurrentCellChanged, _ AddressOf GenDataGrid_CurrentCellChanged End Sub
Sub GenDataGrid_CurrentCellChanged(ByVal sender As Object, _ ByVal e As System.EventArgs) Dim grid As DataGrid = DirectCast(sender, DataGrid) Dim columnsToSkip() As Integer = DirectCast(grid.Tag, Integer()) Dim currColIndex As Integer = grid.CurrentCell.ColumnNumber If Array.IndexOf(columnsToSkip, currColIndex) > -1 Then SendKeys.Send("{TAB}") End If End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|