CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Table Control

  1. #1
    Join Date
    Sep 2000
    Location
    UK
    Posts
    122

    Table Control

    Hi, I am quite new to VB.
    But I need a control that acts like a table.
    Where the user can click in any field in the table and enter a value.
    Each column in my table must ave a header.

    Can anybody suggest what control I should use?


    Regards,
    Jerry Gadd

    Ratings are my only reason for living, so GIVE ME HIGH ONES, or have my death on your consience.
    All code on this page is protected by an SEP field!!!

  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Table Control

    The MS FlexGrid Control.


  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Table Control

    The MSFlexGrid doesn't inherently allow you to edit data in a cell. Here is the code that illustrates a workaround, using a textbox.

    Place a textbox on a form and set the following properties

    Appearance = 0 'Flat
    BorderStyle = 0 'None
    Height = 375
    Left = 1560
    TabIndex = 1
    Text
    Top = 240
    Width = 1455

    And a MSFlexGrid control with the following properties

    Height = 2895
    Left = 600
    TabIndex = 0
    Top = 720
    Width = 4215
    Rows = 5
    Cols = 5

    Now paste the following code into the form


    private Sub MSFlexGrid1_DblClick()
    GridEdit Asc(" ")
    End Sub

    private Sub MSFlexGrid1_KeyPress(KeyAscii as Integer)
    GridEdit KeyAscii
    End Sub
    Sub GridEdit(KeyAscii as Integer)
    'use correct font
    Text1.FontName = MSFlexGrid1.FontName
    Text1.FontSize = MSFlexGrid1.FontSize
    Select Case KeyAscii
    Case 0 to Asc(" ")
    Text1 = MSFlexGrid1
    Text1.SelStart = 1000
    Case else
    Text1 = Chr(KeyAscii)
    Text1.SelStart = 1
    End Select

    'position the edit box
    Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left
    Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top
    Text1.Width = MSFlexGrid1.CellWidth
    Text1.Height = MSFlexGrid1.CellHeight
    Text1.Visible = true
    Text1.SetFocus
    End Sub

    private Sub MSFlexGrid1_LeaveCell()
    If Text1.Visible then
    MSFlexGrid1 = Text1
    Text1.Visible = false
    End If
    End Sub

    private Sub MSFlexGrid1_GotFocus()
    If Text1.Visible then
    MSFlexGrid1 = Text1
    Text1.Visible = false
    End If
    End Sub

    private Sub Text1_KeyDown(KeyCode as Integer, Shift as Integer)
    Select Case KeyCode
    Case vbKeyEscape
    Text1.Visible = false
    MSFlexGrid1.SetFocus
    Case vbKeyReturn
    MSFlexGrid1.SetFocus
    Case vbKeyDown
    MSFlexGrid1.SetFocus
    DoEvents
    If MSFlexGrid1.Row < MSFlexGrid1.Rows - 1 then
    MSFlexGrid1.Row = MSFlexGrid1.Row + 1
    End If
    Case vbKeyUp
    MSFlexGrid1.SetFocus
    DoEvents
    If MSFlexGrid1.Row > MSFlexGrid1.FixedRows then
    MSFlexGrid1.Row = MSFlexGrid1.Row - 1
    End If
    End Select
    End Sub

    private Sub Text1_KeyPress(KeyAscii as Integer)
    'noise suppression
    If KeyAscii = vbKeyReturn then KeyAscii = 0
    End Sub







  4. #4
    Join Date
    Sep 2000
    Location
    UK
    Posts
    122

    Re: Table Control

    Just what I was looking for
    Thank you.!!!!!!!!!!!!!!!!!!!!!

    Regards,
    Jerry Gadd

    Ratings are my only reason for living, so GIVE ME HIGH ONES, or have my death on your consience.
    All code on this page is protected by an SEP field!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured