Results 1 to 6 of 6

Thread: Peculiar behavior flexgrid similar to Martin's editable flexgrid (Solved)

  1. #1

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Peculiar behavior flexgrid similar to Martin's editable flexgrid (Solved)

    Hello guys! Long time no see... I have been very busy so I wasn't able to come on before.

    I tried browsing the forum for an answer to this problem I found out. This bug occured when I was coding an editable flexgrid which is similar to the one Martin posted in the CodeBank and it is a particular one.

    I will attach the project so you all can see what I mean. The problem seems to happen when you have a column which width is greater than the flexgrid's width.

    When you click on that cell the TextBox is located on the place of the cell but since the width is greater than the flexgrid's then it covers the whole control and surpases it.

    How can I avoid this to happen? I mean, I thought I could do something as checking the position and the width to see if it surpases the control's width limit... But if I did that and the grid has its scrollbar then I would need to know the width of the scrollbar to substract it and I am afraid I don't know how to do that.

    Any suggestions or a workaround?

    Thanks in advance!
    Attached Files Attached Files
    Last edited by Tec-Nico; Apr 8th, 2004 at 02:14 AM.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Use the GetSystemMetrics API to find the width of system scrollbars (among other things).

    VB Code:
    1. 'in the general declarations of the form
    2. 'or make the following public and place in a code module
    3. Private Const SM_CXHSCROLL = 21
    4. Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    5.  
    6. Private Sub mfgTest_Click()
    7.     Dim lngScrollWidth As Long
    8.  
    9.     'the GetSystemMetrics return value is in Pixels
    10.     'use ScaleX method to convert to the Form's ScaleMode.
    11.     lngScrollWidth = ScaleX(GetSystemMetrics(SM_CXHSCROLL), vbPixels, Me.ScaleMode)
    12.  
    13.     With txtCell
    14.         .Left = mfgTest.Left + mfgTest.CellLeft
    15.         .Top = mfgTest.Top + mfgTest.CellTop
    16.        
    17.         'make sure the cell width is not greater than the control width
    18.         'and check if only a portion of the cell is being displayed.
    19.         If mfgTest.CellWidth + mfgTest.CellLeft > mfgTest.Width Then
    20.             'set the textbox width to the visible portion of the
    21.             'cell.  Note this assumes the ScrollBar is always visible.
    22.  
    23.             'use GetScrollBarInfo to find out if the scollbar is visible
    24.             .Width = (mfgTest.Width - mfgTest.CellLeft) - lngScrollWidth
    25.         Else
    26.             .Width = mfgTest.CellWidth
    27.         End If
    28.         .Height = mfgTest.CellHeight
    29.    '... rest of code

  3. #3

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Thank you, Bruce. Please let me try it.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  4. #4

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Yes, it worked like a charm!

    I remember I saw that API before but I didn't think about using it (Because I didn't remember about the API and also because I forgot where that example I saved is)

    Other thing... How could you tell if a Cell is partially shown?

    I mean, part of the Cell could be hidden by one of the scrollbars and the ColIsVisible or RowIsVisible properties will "lie" about it... Do you know if there is a way to tell?

    (And excuse me for being an annoyance, but how would you use the GetScrollBarInfo API to know if it is visible or not? Does it need a special Type like other APIs?)
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  5. #5

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    I made some research and I came to this code which seems to be working fine.

    Here I post it.

    Anyway, I would like to know if there is a way to know if a cell is just partially visible (it may be or not hidden by a scrollbar and just part of it would be visible.. I will upload a picture to show so)
    Attached Files Attached Files
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  6. #6

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Nevermind, here is a way:

    VB Code:
    1. Private Const SM_CXHSCROLL = 3 '21
    2. Private Const SM_CXVSCROLL = 2 '22
    3.  
    4. Private Const SIF_RANGE = &H1
    5. Private Const SIF_PAGE = &H2
    6. Private Const SIF_POS = &H4
    7. Private Const SIF_DISABLENOSCROLL = &H8
    8. Private Const SIF_TRACKPOS = &H10
    9. Private Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)
    10.  
    11. Private Const SB_HORZ = 0
    12. Private Const SB_VERT = 1
    13. Private Const SB_BOTH = 3
    14.  
    15. Private Type SCROLLINFO
    16.  cbSize As Long ' Size of structure
    17.  fMask As Long ' Which value(s) you are changing
    18.  nMin As Long ' Minimum value of the scroll bar
    19.  nMax As Long ' Maximum value of the scroll bar
    20.  nPage As Long ' Large-change amount
    21.  nPos As Long ' Current value
    22.  nTrackPos As Long ' Current scroll position
    23. End Type
    24.  
    25. Private Declare Function GetScrollInfo Lib "user32" (ByVal hWnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long
    26. Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    27.  
    28. Private Function GetScrollBarInfo(hWnd As Long, Optional lType As Long = SB_VERT) As SCROLLINFO
    29.  Dim SBI As SCROLLINFO
    30.  SBI.cbSize = Len(SBI)
    31.  SBI.fMask = SIF_ALL
    32.  GetScrollInfo hWnd, lType, SBI
    33.  GetScrollBarInfo = SBI
    34. End Function
    35.  
    36. Public Function isColTotallyVisible(mfgGiven As MSFlexGrid, iCol As Long) As Boolean
    37.  Dim iScrollWidth As Long
    38.  Dim infoScroll As SCROLLINFO
    39.  
    40.  infoScroll = GetScrollBarInfo(mfgGiven.hWnd)
    41.  If infoScroll.nMax <> infoScroll.nMin Then
    42.   iScrollWidth = mfgGiven.Parent.ScaleX(GetSystemMetrics(SM_CXHSCROLL), vbPixels, mfgGiven.Parent.ScaleMode)
    43.  End If
    44.  
    45.  isColTotallyVisible = mfgGiven.ColPos(iCol) + mfgGiven.ColWidth(iCol) <= mfgGiven.Width - iScrollWidth
    46. End Function
    47.  
    48. Public Function isRowTotallyVisible(mfgGiven As MSFlexGrid, iRow As Long) As Boolean
    49.  Dim iScrollHeight As Long
    50.  Dim infoScroll As SCROLLINFO
    51.  
    52.  infoScroll = GetScrollBarInfo(mfgGiven.hWnd, SB_HORZ)
    53.  If infoScroll.nMax <> infoScroll.nMin Then
    54.   iScrollHeight = mfgGiven.Parent.ScaleX(GetSystemMetrics(SM_CXVSCROLL), vbPixels, mfgGiven.Parent.ScaleMode)
    55.  End If
    56.  
    57.  isRowTotallyVisible = mfgGiven.RowPos(iRow) + mfgGiven.RowHeight(iRow) <= mfgGiven.Height - iScrollHeight
    58. End Function

    I must say that part of the code (The GetScrollBarInfo procedure) was not written by me... I found it in the forum but I forgot the name of who posted it.

    Whoever he is, Thanks!
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

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