Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Listbox question

I have a 2 listbox that has the same value or contents are the same.

My question is how can i disable the other if the first value has been already selected?

Listbox 1
A <- Selected
B
C
D


Listbox 2
A <- Cannot be selected
B
C
D

I have tried using if but i have a 20 list items in my listbox.
0
TheGameEdge
Asked:
TheGameEdge
1 Solution
 
twalgraveCommented:
You cannot disable individual items from a listbox.  Sorry!

What you could do is on the Click event, scan listbox2 and see if that item is already selected.  If it is, set the listindex of listbox1 to -1 (not friendly behavior!).
0
 
twalgraveCommented:
What I mean to say is something like this:

private sub List1_Click()
   if list1.listindex > -1 then
      if list2.listindex > -1 then
         if list2.list(list2.listindex) = list1.list(list1.listindex) then
            list1.listindex = -1
         endif
      endif
   endif
end sub
0
 
luisseixasCommented:
Try to do somethig like this...



procedure TForm1.List1Click(Sender: TObject);
var i: Integer;
begin
  For i:=0 to List1.Items.Count-1 do
    If (List0.Selected[i]) AND (List1.Selected[i])
      then List1.ItemIndex:=-1;
end;
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
DabasCommented:
I suggest you use listview in report style instead of listboxes

Same effect and once you have the hang of it, so much easier to format!
An extra advantage is that you have extra features such as extra columns, checkboxes, etc

Dabas
0
 
cybeonixCommented:
What you are trying to do is mutual exclusion, I assume. You might consider using is the listview control and enable the LVS_EX_CHECKBOXES option for the Extended Styles.

You can check the status of these checkboxes and use them however you wish, if its checked, you can prevent it from being unchecked. (you could enable the checkbox simply when the user selects the item in the list)
0
 
FaithRavenCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept twalgrave's comment
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

FaithRaven
EE Cleanup Volunteer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now