• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

List Boxes, Moving Items (Removing Then Adding)

I'm sure you will know what this code does...

Private Sub cmdP1BuyHood_Click()

Dim I As Integer
If lstBank.ListIndex = -1 Then Exit Sub
For I = lstBank.ListCount - 1 To 0 Step -1
If lstBank.Selected(I) = True Then
PropertyListP1.AddItem PropertyListP1.List(I)
lstBank.RemoveItem I
End If
Next I

End Sub

Well its for a monopoly game. I have 3 list boxes. The code above removes an item from the Bank list box and adds it to player 1's list box. Its not exactly what I need. I need to select 1 of 24 items in the list box and then click the command button however this obviously gives the user the choice of property. I only want them to be able to purchase the property they have
landed on.

So when the BUY button is pressed they buy the current property which is also displayed on a picture box using text boxes and
labels. I cant get my head around how I go about doing this but what I'm thinking is pressing the BUY button, checking the 'Title' of the property in the label and using this to add this property's item to the players list of bought property and removing it from the banks list. Is this possible and how would I do it?

So I have a command button, a list box holiding the property, a list box holding the players bought property at first empty, a picture box holding a label and text boxes with 1 label which holds the propertys name that is currently occupied.
0
Ryan Bayne
Asked:
Ryan Bayne
  • 3
  • 2
2 Solutions
 
dr_binksCommented:
you could just say (at the very start of you program)
<nameoflist>.enabled=false
e.g. list1.enabled = false

you can still add/del items and make them selected.
the user cant click on the list.

'when player lands on property
for 1=0 to list.listcount-1
 if label.caption = list.list(i) then
 list.selectitem(i)=true
 exit for
next

'delete from bank
for 1=0 to list.listcount-1
 if label.caption = list.list(i) then
 list.removeitem(i)
 exit for
next

I think this is what you wanted

hope it helps

~Binks


0
 
r_a_j_e_s_hCommented:
a small change in previous code,. that's it... i know that is a typing mistake.. anyhow iam posting that...
******************************************************************************************

you could just say (at the very start of you program)
<nameoflist>.enabled=false
e.g. list1.enabled = false

you can still add/del items and make them selected.
the user cant click on the list.

'when player lands on property
for i=0 to list.listcount-1
 if label.caption = list.list(i) then
 list.selectitem(i)=true
 exit for
next

'delete from bank
for i=0 to list.listcount-1
 if label.caption = list.list(i) then
 list.removeitem(i)
 exit for
next

I think this is what you wanted

hope it helps

~Binks
0
 
dr_binksCommented:
heh, I just noticed the mistake I made, cheers :)
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.

 
Ryan BayneWordPress DeveloperAuthor Commented:
Let me confirm. This code checks the label and enables its sell. It doesnt allow the list box to be clicked on.
Would it be simple to enable selection however not allow the purchase of anything apart from the property that is also
displayed in label that allready displays the property name? Basically, check the label to see what text it holds and check to see if there is an item in the list with that name. If so THEN enable sale. If not no sale however when the player clicks on an item in the list I plan to pop up a new window with a title deed.

Thanks for the help so far.
0
 
r_a_j_e_s_hCommented:
i also agree with u modulo.... dr_binks  should be getting the points not me...


regards

rajesh
0
 
dr_binksCommented:
Thanks Modula :)
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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