Results 1 to 40 of 1650

Thread: VBFlexGrid Control (Replacement of the MSFlexGrid control)

Threaded View

  1. #11
    Hyperactive Member
    Join Date
    May 2018
    Location
    Russia
    Posts
    343

    Arrow Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Calcu View Post
    It's possible to autoadjust the width of the column "before" selecting anyhing ?
    Yes, you may use the ColWidth property and the TextWidth function in the ComboBeforeDropDown or ComboCloseUp events.



    Edited:
    The code below is edited in accordance with the post #1283 by Krool.

    Code:
    Const COL_COMBO = 1
    Private nOldColWidth As Long, bColWidthIsChanged As Boolean
    
    Private Sub Command3_Click()
       With VBFlexGrid1
          .ColComboCue(COL_COMBO) = FlexComboCueDropDown
          .ColComboMode(COL_COMBO) = FlexComboModeDropDown
          .ColComboItems(COL_COMBO) = "Arnold|Bob|Charlie|David"
       End With
    End Sub
    
    Private Sub VBFlexGrid1_ComboBeforeDropDown( _
             ByVal Reason As VBFLXGRD17.FlexComboDropDownReasonConstants, _
                   Cancel As Boolean)
    
       Dim nTextWidth  As Long, nNewTextWidth As Long
       Dim aComboItems As Variant, i As Long
    
       With VBFlexGrid1
          If (.EditCol = COL_COMBO) And (LenB(.ColComboItems(COL_COMBO))) Then
             aComboItems = Split(.ColComboItems(COL_COMBO), "|")
             For i = LBound(aComboItems) To UBound(aComboItems)
                nNewTextWidth = .TextWidth(aComboItems(i), .EditRow, .EditCol)
                If nTextWidth < nNewTextWidth Then nTextWidth = nNewTextWidth
             Next
             nOldColWidth = .ColWidth(COL_COMBO)
             .ColWidth(COL_COMBO) = nTextWidth \ 15 * 15
             bColWidthIsChanged = True
          End If
       End With
    End Sub
    
    Private Sub VBFlexGrid1_ComboCloseUp()
       If bColWidthIsChanged Then
          VBFlexGrid1.ColWidth(COL_COMBO) = nOldColWidth
          bColWidthIsChanged = False
       End If
    End Sub
    Last edited by Nouyana; Feb 28th, 2024 at 08:58 AM. Reason: Code improvements

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