disable list element

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ike

    disable list element

    Does anyone know how to disable a list box element in VB 6 ? Thanks Ike


  • Karl E. Peterson

    #2
    Re: disable list element

    Ike wrote:[color=blue]
    > Does anyone know how to disable a list box element in VB 6 ?[/color]

    No can do. It's all or nothing.
    --


    Comment

    • Raoul Watson

      #3
      Re: disable list element


      "Ike" <rxv@hotmail.co m> wrote in message
      news:xnCjg.5463 $o4.4055@newsre ad2.news.pas.ea rthlink.net...[color=blue]
      > Does anyone know how to disable a list box element in VB 6 ? Thanks Ike
      >[/color]

      Well.. you could ignore any click or double-click if that constitute
      "disable"
      But if you want the highlight to skip, no..


      Comment

      • Jan Hyde

        #4
        Re: disable list element

        "Ike" <rxv@hotmail.co m>'s wild thoughts were released on
        Tue, 13 Jun 2006 17:14:05 GMT bearing the following fruit:
        [color=blue]
        >Does anyone know how to disable a list box element in VB 6 ? Thanks Ike[/color]

        You could use a grid instead then you have a lot more
        control over how things work.




        Jan Hyde (VB MVP)

        --
        When he handed her a note written on tissue paper, the teacher said it was a flimsy excuse.
        (Stan Kegel)

        Comment

        • Angelo

          #5
          Re: disable list element

          Ike wrote:[color=blue]
          > Does anyone know how to disable a list box element in VB 6 ?[/color]

          Well you can do you'r script like it's first checking if the item text is
          not that text then do the actions, else ignore it.

          Hope it was helpfully.


          Comment

          • Rick Rothstein

            #6
            Re: disable list element

            > Does anyone know how to disable a list box element in VB 6 ? Thanks Ike

            Following up on Jan's suggestion, here is some code that will make a
            MSFlexGrid act like a ListBox, but where you can disable one or more items
            in it. Give the code a try and post back with any questions you may have
            about how any part of it works. Start a new project and add an MSFlexGrid to
            the form and paste the code below into the form's code window... then run
            the project. Note: The code is rough and rather quickly constructed... so it
            may contains small flaws that might surface when you test it out. If so, let
            me know and I'll see if I can patch it for you. Even if you figure out how
            to patch it yourself, please post any fixes back to this thread so that the
            archives are complete. Thanks.

            Rick

            Option Explicit

            ' These 3 declares are needed for functionality
            Dim PreviousRow As Long
            Dim DisabledColor As Long
            Dim SkipEnterCellCh eck As Boolean

            ' The following is for control grid display stuff
            Dim RowsToDisplay As Long
            Const NumberOfLinesOf Text = 30
            Const VisibleRows As Long = 12

            Private Sub Command1_Click( )
            DisableRow 6, False
            MSFlexGrid1.Set Focus
            End Sub

            Private Sub Form_Load()
            Dim Index As Long
            Const WidthOfGrid As Long = 3000
            DisabledColor = RGB(190, 190, 190)
            With MSFlexGrid1
            .Font = "Arial"
            .Font.Size = 10
            .Cols = 1
            .Rows = NumberOfLinesOf Text
            .FixedCols = 0
            .FixedRows = 0
            If NumberOfLinesOf Text > VisibleRows Then
            RowsToDisplay = VisibleRows
            .ScrollBars = flexScrollBarVe rtical
            Else
            RowsToDisplay = NumberOfLinesOf Text
            End If
            .Height = RowsToDisplay * (.RowHeight(0) + .GridLineWidth)
            .Width = WidthOfGrid
            .ColWidth(0) = .Width
            .Appearance = flexFlat
            .FocusRect = flexFocusNone
            .BackColor = vbWhite
            .ForeColor = vbBlack
            .BackColorSel = vbBlack
            .ForeColorSel = vbWhite
            .ScrollTrack = True
            ' Color grid lines if shown
            .GridColor = &HC0C0C0
            ' Hide the grid lines, remove this line to show them
            .GridLines = flexGridNone
            ' Fill the grid with something to start with
            For Index = 0 To .Rows - 1
            .TextMatrix(Ind ex, 0) = "Text for Line #" & CStr(Index)
            Next
            ' Just to make sure you can see the grid for this example
            .Move 120, 120
            ' Mark all rows as enabled
            For Index = 0 To .Rows - 1
            .RowData(Index) = 0
            Next
            ' NOW, let us disable some items in the list
            DisableRow 0
            DisableRow 1
            DisableRow 6
            DisableRow 7
            DisableRow 8
            DisableRow 27
            DisableRow 28
            DisableRow 29
            ' Attempt to set Row #0 as the current row; if it is
            ' diabled, the EnterCell event will force it to find
            ' the first non-disabled row automatically
            .Row = 0
            ' For initialization purposes, we set the PreviousRow
            ' variable to whatever non-disabled row becomes the
            ' default
            PreviousRow = .Row
            End With
            End Sub

            Private Sub MSFlexGrid1_Cli ck()
            With MSFlexGrid1
            Debug.Print "Row #" & .Row & " was clicked"
            End With
            End Sub

            Private Sub MSFlexGrid1_Ent erCell()
            If SkipEnterCellCh eck Then Exit Sub
            With MSFlexGrid1
            If .RowData(.Row) = True Then FindNextNonDisa bledRow
            End With
            End Sub

            Private Sub MSFlexGrid1_Lea veCell()
            With MSFlexGrid1
            PreviousRow = .Row
            End With
            End Sub

            Private Sub MSFlexGrid1_Mou seDown(Button As Integer, _
            Shift As Integer, x As Single, y As Single)
            With MSFlexGrid1
            If .RowData(.Row) = True Then FindNextNonDisa bledRow
            ' Needed to stop contiguous row selections
            .Redraw = False
            PreviousRow = .Row
            End With
            End Sub

            Private Sub MSFlexGrid1_Mou seUp(Button As Integer, _
            Shift As Integer, x As Single, y As Single)
            With MSFlexGrid1
            If .Rows - .TopRow < VisibleRows Then
            .TopRow = .Rows - VisibleRows
            End If
            ' Needed to stop contiguous row selections
            .RowSel = MSFlexGrid1.Row
            .Redraw = True
            End With
            End Sub

            Private Sub MSFlexGrid1_Scr oll()
            With MSFlexGrid1
            If .TopRow > NumberOfLinesOf Text - RowsToDisplay Then
            .TopRow = NumberOfLinesOf Text - RowsToDisplay
            End If
            End With
            End Sub

            ' Use this Sub to disable an item (DisableItem = True, the default)
            ' and to reenable an item again (pass DisableItem = False) to the Sub
            Sub DisableRow(RowN um As Long, Optional DisableItem As Boolean = True)
            Dim CurrentRow As Long
            SkipEnterCellCh eck = True
            With MSFlexGrid1
            CurrentRow = .Row
            .RowData(RowNum ) = True
            .Col = 0
            .Row = RowNum
            If DisableItem Then
            .CellForeColor = DisabledColor
            Else
            .CellForeColor = .ForeColor
            .RowData(RowNum ) = False
            .Row = CurrentRow
            End If
            If CurrentRow = RowNum Then
            FindNextNonDisa bledRow
            End If
            End With
            SkipEnterCellCh eck = False
            End Sub

            Sub FindNextNonDisa bledRow()
            Dim Index As Long
            With MSFlexGrid1
            If PreviousRow < .Row Then
            For Index = .Row + 1 To .Rows - 1
            If .RowData(Index) = False Then
            .Row = Index
            Exit Sub
            End If
            Next
            For Index = .Row - 1 To 0 Step -1
            If .RowData(Index) = False Then
            .Row = Index
            Exit Sub
            End If
            Next
            Else
            For Index = .Row - 1 To 0 Step -1
            If .RowData(Index) = False Then
            .Row = Index
            Exit Sub
            End If
            Next
            For Index = .Row + 1 To .Rows - 1
            If .RowData(Index) = False Then
            .Row = Index
            Exit Sub
            End If
            Next
            End If
            End With
            End Sub


            Comment

            Working...