flavo
asked on
tab in datagrid
When a user hits the tab control in a datagrid, i would like it to go to the next row, not the next coloumn in the dg.
Does anyone have an override for this??
Does anyone have an override for this??
ASKER
hmm.. not sure if it will work, i removed all my textBox controls from the dg to stop the editing
Try this
------------------
Class MyGrid
Inherits System.Windows.Forms.DataG rid
Private Const WM_KEYDOWN = &H100
Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
If (keyData = Keys.Tab) Then
Me.CurrentRowIndex = Me.CurrentRowIndex + 1
'Me.CurrentCell = New DataGridCell(Me.CurrentRow Index, 0)
Return True ' //ignore it
End If
Return MyBase.ProcessDialogKey(ke yData)
End Function
End Class
---------------
Regrads
prakash
------------------
Class MyGrid
Inherits System.Windows.Forms.DataG
Private Const WM_KEYDOWN = &H100
Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys)
If (keyData = Keys.Tab) Then
Me.CurrentRowIndex = Me.CurrentRowIndex + 1
'Me.CurrentCell = New DataGridCell(Me.CurrentRow
Return True ' //ignore it
End If
Return MyBase.ProcessDialogKey(ke
End Function
End Class
---------------
Regrads
prakash
ASKER
Ill test when i get home!
Thanks
Dave
Thanks
Dave
Ok flavo
ASKER
ok.. i tested it with
Protected Overrides Function ProcessDialogKey(ByVal keyData As System.windows.forms.Keys) As Boolean
If keyData = Keys.Tab Then
If Me.CurrentRowIndex = -1 Then
Me.CurrentRowIndex = 1
ElseIf Me.CurrentRowIndex = Me.VisibleRowCount Then
'do nothing
Else
Me.CurrentRowIndex = Me.CurrentRowIndex + 1
Return True
End If
End If
Return MyBase.ProcessDialogKey(ke yData)
End Function
sort of works within the dg, but id like it to got back to the control with a tab index of 1 when it gets to the end..
Can this be done?
Dave
Protected Overrides Function ProcessDialogKey(ByVal keyData As System.windows.forms.Keys)
If keyData = Keys.Tab Then
If Me.CurrentRowIndex = -1 Then
Me.CurrentRowIndex = 1
ElseIf Me.CurrentRowIndex = Me.VisibleRowCount Then
'do nothing
Else
Me.CurrentRowIndex = Me.CurrentRowIndex + 1
Return True
End If
End If
Return MyBase.ProcessDialogKey(ke
End Function
sort of works within the dg, but id like it to got back to the control with a tab index of 1 when it gets to the end..
Can this be done?
Dave
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>>Me.FirstControl.Focus()
Yeah, but the Me imply's the datagrid, not the form in which it "lives"
Dave
Yeah, but the Me imply's the datagrid, not the form in which it "lives"
Dave
Create the the datagrid object with this sytax
dim mygrid1 as new MyGrid(Me.TextBox1)
pass the first control to MyGrid Constructor's first argument
Regards
Prakash
dim mygrid1 as new MyGrid(Me.TextBox1)
pass the first control to MyGrid Constructor's first argument
Regards
Prakash
ASKER
ahhhh... didnt see that, that's why it bombed out...
Ill test when i get home!
Thanks
Ill test when i get home!
Thanks
Ok dave
Regards
Prakash
Regards
Prakash
ASKER
nope no good. Object Not set to an instance of an object or whatever it says..
ASKER
seems harder than i though... 500 it is!
Can you post your code ..
Regards
Prakash
Regards
Prakash
ASKER
Component class
Option Strict Off
Option Explicit On
Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class customDG
Inherits System.ComponentModel.Comp onent
#Region " Component Designer generated code "
Public Sub New(ByVal Container As System.ComponentModel.ICon tainer)
MyClass.New()
'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Component overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
components = New System.ComponentModel.Cont ainer
End Sub
#End Region
Public Class MyDataGrid
Inherits DataGrid
Private FirstControl As Control
Private oldSelectedRow As Integer
'Fields
'Constructors
'Events
'Methods
Public Sub New()
'Warning: Implementation not found
End Sub
Protected Overloads Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
'don't call the base class if left mouse down
If (e.Button <> MouseButtons.Left) Then
MyBase.OnMouseMove(e)
End If
End Sub
Protected Overloads Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
'don't call the base class if left mouse down
If e.Button <> MouseButtons.Left Then
Exit Sub
End If
'don't call the base class if in header
Try
Dim hti As DataGrid.HitTestInfo
hti = Me.HitTest(New Point(e.X, e.Y))
If (hti.Type = DataGrid.HitTestType.Cell) Then
If (oldSelectedRow > -(1)) Then
Me.UnSelect(oldSelectedRow )
End If
oldSelectedRow = -(1)
MyBase.OnMouseUp(e)
Else
If (hti.Type = DataGrid.HitTestType.RowHe ader) Then
If (oldSelectedRow > -(1)) Then
Me.UnSelect(oldSelectedRow )
End If
If ((Control.ModifierKeys And Keys.Shift) _
= 0) Then
MyBase.OnMouseUp(e)
Else
Me.CurrentCell = New DataGridCell(hti.Row, hti.Column)
End If
Me.Select(hti.Row)
oldSelectedRow = hti.Row
End If
End If
Dim pt = New Point(e.X, e.Y)
If hti.Type = DataGrid.HitTestType.Cell Then
Me.CurrentCell = New DataGridCell(hti.Row, hti.Column)
Me.Select(hti.Row)
End If
Catch
'used for the case when the row that was last selected is now deleted - ie remove year form
End Try
End Sub
Public Sub New(ByRef FirstControl As Control)
MyBase.New()
Me.FirstControl = FirstControl
End Sub
Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
If (keyData = Keys.Tab) Then
If Me.CurrentRowIndex = -1 Then
Me.CurrentRowIndex = 1
Return True
ElseIf Me.CurrentRowIndex = Me.VisibleRowCount - 2 Then
Me.FirstControl.Focus()
Return True
Else
Me.CurrentRowIndex = Me.CurrentRowIndex + 1
Return True
End If
Return True ' //ignore it
End If
Return MyBase.ProcessDialogKey(ke yData)
End Function
End Class
End Class
form1 class - bits we are interested in
Friend WithEvents dgLineItems As customDG.MyDataGrid
'......
Me.dgLineItems = New customDG.MyDataGrid(Me.cbo TaxYear)
dave
Option Strict Off
Option Explicit On
Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class customDG
Inherits System.ComponentModel.Comp
#Region " Component Designer generated code "
Public Sub New(ByVal Container As System.ComponentModel.ICon
MyClass.New()
'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Component overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.Debugg
components = New System.ComponentModel.Cont
End Sub
#End Region
Public Class MyDataGrid
Inherits DataGrid
Private FirstControl As Control
Private oldSelectedRow As Integer
'Fields
'Constructors
'Events
'Methods
Public Sub New()
'Warning: Implementation not found
End Sub
Protected Overloads Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
'don't call the base class if left mouse down
If (e.Button <> MouseButtons.Left) Then
MyBase.OnMouseMove(e)
End If
End Sub
Protected Overloads Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
'don't call the base class if left mouse down
If e.Button <> MouseButtons.Left Then
Exit Sub
End If
'don't call the base class if in header
Try
Dim hti As DataGrid.HitTestInfo
hti = Me.HitTest(New Point(e.X, e.Y))
If (hti.Type = DataGrid.HitTestType.Cell)
If (oldSelectedRow > -(1)) Then
Me.UnSelect(oldSelectedRow
End If
oldSelectedRow = -(1)
MyBase.OnMouseUp(e)
Else
If (hti.Type = DataGrid.HitTestType.RowHe
If (oldSelectedRow > -(1)) Then
Me.UnSelect(oldSelectedRow
End If
If ((Control.ModifierKeys And Keys.Shift) _
= 0) Then
MyBase.OnMouseUp(e)
Else
Me.CurrentCell = New DataGridCell(hti.Row, hti.Column)
End If
Me.Select(hti.Row)
oldSelectedRow = hti.Row
End If
End If
Dim pt = New Point(e.X, e.Y)
If hti.Type = DataGrid.HitTestType.Cell Then
Me.CurrentCell = New DataGridCell(hti.Row, hti.Column)
Me.Select(hti.Row)
End If
Catch
'used for the case when the row that was last selected is now deleted - ie remove year form
End Try
End Sub
Public Sub New(ByRef FirstControl As Control)
MyBase.New()
Me.FirstControl = FirstControl
End Sub
Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys)
If (keyData = Keys.Tab) Then
If Me.CurrentRowIndex = -1 Then
Me.CurrentRowIndex = 1
Return True
ElseIf Me.CurrentRowIndex = Me.VisibleRowCount - 2 Then
Me.FirstControl.Focus()
Return True
Else
Me.CurrentRowIndex = Me.CurrentRowIndex + 1
Return True
End If
Return True ' //ignore it
End If
Return MyBase.ProcessDialogKey(ke
End Function
End Class
End Class
form1 class - bits we are interested in
Friend WithEvents dgLineItems As customDG.MyDataGrid
'......
Me.dgLineItems = New customDG.MyDataGrid(Me.cbo
dave
your codes runs on my machine well.
Can you say which line you get the error
Prakash
Can you say which line you get the error
Prakash
ASKER
It dies when i tab trough the controls, the loop trough all the controls back to the datagrid again
please check are you have codes like this . if yes remove it.
Me.dgLineItems = New customDG.MyDataGrid()
please post the complete error message.
Regards
Prakash
Me.dgLineItems = New customDG.MyDataGrid()
please post the complete error message.
Regards
Prakash
ASKER
ok... Ill belive you mate... Im too tired.
Thanks for all your help, i cant belive it took me this long to get this!
Dave
Thanks for all your help, i cant belive it took me this long to get this!
Dave
Thank you flavo
Reagards
Prakash
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp?print=836