?
Solved

tab in datagrid

Posted on 2004-10-24
20
Medium Priority
?
181 Views
Last Modified: 2012-05-05
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??  
0
Comment
Question by:flavo
  • 10
  • 10
20 Comments
 
LVL 10

Expert Comment

by:prakash_prk
ID: 12397737
0
 
LVL 34

Author Comment

by:flavo
ID: 12397742
hmm.. not sure if it will work, i removed all my textBox controls from the dg to stop the editing
0
 
LVL 10

Expert Comment

by:prakash_prk
ID: 12397800
Try this
------------------
Class MyGrid
    Inherits System.Windows.Forms.DataGrid
    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.CurrentRowIndex, 0)
            Return True ' //ignore it
        End If
        Return MyBase.ProcessDialogKey(keyData)
    End Function
End Class
---------------
Regrads
prakash
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
LVL 34

Author Comment

by:flavo
ID: 12397806
Ill test when i get home!

Thanks

Dave
0
 
LVL 10

Expert Comment

by:prakash_prk
ID: 12397821
Ok flavo
0
 
LVL 34

Author Comment

by:flavo
ID: 12398215
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(keyData)
        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
0
 
LVL 10

Accepted Solution

by:
prakash_prk earned 2000 total points
ID: 12398474
Try this
------------------
Class MyGrid
    Inherits System.Windows.Forms.DataGrid
    Private Const WM_KEYDOWN = &H100
    Private FirstControl As Control

    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(keyData)
    End Function
End Class
------------------------------------------
Regards
Prakash
0
 
LVL 34

Author Comment

by:flavo
ID: 12398556
>>Me.FirstControl.Focus()
Yeah, but the Me imply's the datagrid, not the form in which it "lives"

Dave
0
 
LVL 10

Expert Comment

by:prakash_prk
ID: 12407539
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
0
 
LVL 34

Author Comment

by:flavo
ID: 12407549
ahhhh... didnt see that, that's why it bombed out...

Ill test when i get home!

Thanks
0
 
LVL 10

Expert Comment

by:prakash_prk
ID: 12407557
Ok dave

Regards
Prakash
0
 
LVL 34

Author Comment

by:flavo
ID: 12419400
nope no good.  Object Not set to an instance of an object or whatever it says..
0
 
LVL 34

Author Comment

by:flavo
ID: 12419463
seems harder than i though...  500 it is!
0
 
LVL 10

Expert Comment

by:prakash_prk
ID: 12419669
Can you post your code ..

Regards
Prakash
0
 
LVL 34

Author Comment

by:flavo
ID: 12419721
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.Component

#Region " Component Designer generated code "

    Public Sub New(ByVal Container As System.ComponentModel.IContainer)
        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.IContainer

    '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.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container
    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.RowHeader) 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(keyData)
        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.cboTaxYear)

dave
0
 
LVL 10

Expert Comment

by:prakash_prk
ID: 12419779
your codes runs on my machine well.

Can you say which line you get the error

Prakash
0
 
LVL 34

Author Comment

by:flavo
ID: 12421236
It dies when i tab trough the controls, the loop trough all the controls back to the datagrid again
0
 
LVL 10

Expert Comment

by:prakash_prk
ID: 12421344
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
0
 
LVL 34

Author Comment

by:flavo
ID: 12421412
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
0
 
LVL 10

Expert Comment

by:prakash_prk
ID: 12421477


Thank you flavo

Reagards
Prakash
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
An ASP.NET Web Form User Control is not newly introduced in ASP.NET. In fact, it was an old technology yet still playing a role to generate web content, especially when we want to use it to have a better and easy way to control part of the web conte…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question