Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabling the List box Items

Status
Not open for further replies.

pandi

Programmer
Dec 12, 2001
22
0
0
MY
Hai

I am using the List box with style as checked. For some group of users, I want to prevent them not to check few list items. That means depending upon the group I have to Enable/Disable the list box items. Any ideas of doing like this?

Thanks in advance.
Pandi
 
I'm not 100% how you would go about allowing users to only access certain items in the ListBox. Might you be able to check what group the user is in and then populate the listbox accordingly with only the items that they can use??

Harleyquinn

---------------------------------
For tsunami relief donations
 
pandi,

The other approach would be maintaining INI file in some protected location. User logs in and your application reads rights from INI file enabling/disabling certain areas of your GUI. Even better approach assumes admin database for this functionality.

The approach Harleyquinn suggests fits this scenario. ACCESS database has features supporting group mult-level rights.

vladk
 
Let us suppose you have 5 groups.
Let us suppose you have 12 selections in your listbox.
Group 1 is allowed to select either of options 1, 5, 7, 8, 11
Group 2 is allowed to select either of options 2, 5, 7, 10
and so on.
Create a variable myGroups(5)
then:
myGroups(1) = "(1), (5), (7), (8), (11)"
myGroups(2) = "(2), (5), (7), (10)"
and so on
Let's say in advance you have the current user group assigned to a variable called G.

Private Sub myListBox_ItemCheck(Item As Integer)
mySelected = "(" & Item & ")"
if instr(myGroups(G), mySelected) = 0 then
myListBox.Selected(Item) = False
end if
End Sub

This forces the check box to remain unchecked even when clicked if the item is not of this group's allowance.

Hope that helps.

Eman_2005
Technical Communicator
 
eman2005's suggestion is kind of like what I did for the same situation that I had ( certain items in ListBox that I wanted user to be able to see, but not check. )

The problem is that to the user, the uncheckable item looks exactly like the checkable one. If they click on it and it does not check, they may not relaize why it's not checking and it could confuse them.

Since you can't grey out ( at least, as far as I know ) individual listbox items, what I did was to add an asterisk * to the beginning of each list item that was disabled. This way the user could tell which items they were allowed to select, and which they were not.

A little different way to do it would be to use the ItemData for each line to store a value that tells you if the item is checkable or not, instead of using two arrays like eman2005's example shows.

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top