473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

disable list element

Ike
Does anyone know how to disable a list box element in VB 6 ? Thanks Ike
Jun 13 '06 #1
5 6041
Ike wrote:
Does anyone know how to disable a list box element in VB 6 ?


No can do. It's all or nothing.
--
Jun 13 '06 #2

"Ike" <rx*@hotmail.com> wrote in message
news:xn****************@newsread2.news.pas.earthli nk.net...
Does anyone know how to disable a list box element in VB 6 ? Thanks Ike


Well.. you could ignore any click or double-click if that constitute
"disable"
But if you want the highlight to skip, no..
Jun 14 '06 #3
"Ike" <rx*@hotmail.com>'s wild thoughts were released on
Tue, 13 Jun 2006 17:14:05 GMT bearing the following fruit:
Does anyone know how to disable a list box element in VB 6 ? Thanks Ike


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)

Jun 14 '06 #4
Ike wrote:
Does anyone know how to disable a list box element in VB 6 ?


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.
Jun 15 '06 #5
> 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 SkipEnterCellCheck As Boolean

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

Private Sub Command1_Click()
DisableRow 6, False
MSFlexGrid1.SetFocus
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 = NumberOfLinesOfText
.FixedCols = 0
.FixedRows = 0
If NumberOfLinesOfText > VisibleRows Then
RowsToDisplay = VisibleRows
.ScrollBars = flexScrollBarVertical
Else
RowsToDisplay = NumberOfLinesOfText
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(Index, 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_Click()
With MSFlexGrid1
Debug.Print "Row #" & .Row & " was clicked"
End With
End Sub

Private Sub MSFlexGrid1_EnterCell()
If SkipEnterCellCheck Then Exit Sub
With MSFlexGrid1
If .RowData(.Row) = True Then FindNextNonDisabledRow
End With
End Sub

Private Sub MSFlexGrid1_LeaveCell()
With MSFlexGrid1
PreviousRow = .Row
End With
End Sub

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

Private Sub MSFlexGrid1_MouseUp(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_Scroll()
With MSFlexGrid1
If .TopRow > NumberOfLinesOfText - RowsToDisplay Then
.TopRow = NumberOfLinesOfText - 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(RowNum As Long, Optional DisableItem As Boolean = True)
Dim CurrentRow As Long
SkipEnterCellCheck = 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
FindNextNonDisabledRow
End If
End With
SkipEnterCellCheck = False
End Sub

Sub FindNextNonDisabledRow()
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
Jun 15 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: kazio | last post by:
Hello, So, I need to have double linked, circular list (last element point to the first one and first one points to the last one). I thought maybe I could use list container from STL, but...
32
by: Mark Johnson | last post by:
You have an, a, anchor with href link. Can you use a stylesheet to effectively disable the link, so that you can't click on it; that it will appear simply as text?
1
by: Fluffy Convict | last post by:
Does anybody know how to disable only certain options of an option list by a javascript function? With the following function you can disable a option list completely: function disableList() {...
1
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES...
2
by: MT | last post by:
Hi, I am currently validating an XML file against a Schema using XMLValidatingReader. The schema actually contains ranges for particular elements and I have been using it to detect range errors...
4
by: SteveKlett | last post by:
I have a subset of form items that I need to perform different operations on (enable/disable, clear values, change style, etc) rather than hard code the IDs or names I would like to recursively...
1
by: secndChildhood | last post by:
I hope someone can help with this problem: I have a perl cgi form that has a popup_list. Based on a value that is coming in from a database query, I want to either 1) display the value (from...
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
2
by: yong321 | last post by:
My question is not about Javascript programming. I'd like to use a browser, either IE or Firefox or whatever, that allows me to disable a specific Javascript function but not disable Javascript...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.