I am very new to VB.NET and I just need some help in a listbox matter. I
don't need suggestions on how to make the overall code better. I will get
there.
I want to move an item from one list box to another should it be selected in
combination with a button click and selected. I've got the code in there but
it just wont work. Below is the entire code but I only need help with the
following items:
getBtn
inventoryList
itemsList
This is a simple text adventure that I am starting. I just need to know why
the item wont appear in inventoryList when the proper item is selected in
itemsList and the getBtn is used.
Thanks!
Public Class Form1
Inherits System.Windows.Forms.Form
Dim currentLocation As String
Dim livingRoomDesc As String
Dim wigwamexists As Boolean
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents mainLbl As System.Windows.Forms.Label
Friend WithEvents itemsList As System.Windows.Forms.ListBox
Friend WithEvents inventoryList As System.Windows.Forms.ListBox
Friend WithEvents lookBtn As System.Windows.Forms.Button
Friend WithEvents dropBtn As System.Windows.Forms.Button
Friend WithEvents talkBtn As System.Windows.Forms.Button
Friend WithEvents useBtn As System.Windows.Forms.Button
Friend WithEvents getBtn As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.mainLbl = New System.Windows.Forms.Label()
Me.inventoryList = New System.Windows.Forms.ListBox()
Me.itemsList = New System.Windows.Forms.ListBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.Button4 = New System.Windows.Forms.Button()
Me.talkBtn = New System.Windows.Forms.Button()
Me.useBtn = New System.Windows.Forms.Button()
Me.lookBtn = New System.Windows.Forms.Button()
Me.dropBtn = New System.Windows.Forms.Button()
Me.getBtn = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'mainLbl
'
Me.mainLbl.Location = New System.Drawing.Point(8, 8)
Me.mainLbl.Name = "mainLbl"
Me.mainLbl.Size = New System.Drawing.Size(448, 136)
Me.mainLbl.TabIndex = 0
'
'inventoryList
'
Me.inventoryList.Location = New System.Drawing.Point(480, 32)
Me.inventoryList.Name = "inventoryList"
Me.inventoryList.Size = New System.Drawing.Size(128, 121)
Me.inventoryList.TabIndex = 1
'
'itemsList
'
Me.itemsList.Location = New System.Drawing.Point(480, 200)
Me.itemsList.Name = "itemsList"
Me.itemsList.Size = New System.Drawing.Size(128, 121)
Me.itemsList.TabIndex = 2
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(480, 8)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(128, 16)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Inventory"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(480, 160)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(128, 24)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Objects / Persons in Room"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(208, 176)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 5
Me.Button1.Text = "North"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(136, 200)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 6
Me.Button2.Text = "West"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(208, 224)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 7
Me.Button3.Text = "South"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(280, 200)
Me.Button4.Name = "Button4"
Me.Button4.TabIndex = 8
Me.Button4.Text = "East"
'
'talkBtn
'
Me.talkBtn.Location = New System.Drawing.Point(176, 288)
Me.talkBtn.Name = "talkBtn"
Me.talkBtn.TabIndex = 9
Me.talkBtn.Text = "Talk"
'
'useBtn
'
Me.useBtn.Location = New System.Drawing.Point(88, 288)
Me.useBtn.Name = "useBtn"
Me.useBtn.TabIndex = 10
Me.useBtn.Text = "Use"
'
'lookBtn
'
Me.lookBtn.Location = New System.Drawing.Point(0, 288)
Me.lookBtn.Name = "lookBtn"
Me.lookBtn.TabIndex = 11
Me.lookBtn.Text = "Look"
'
'dropBtn
'
Me.dropBtn.Location = New System.Drawing.Point(352, 288)
Me.dropBtn.Name = "dropBtn"
Me.dropBtn.TabIndex = 12
Me.dropBtn.Text = "Drop"
'
'getBtn
'
Me.getBtn.Location = New System.Drawing.Point(264, 288)
Me.getBtn.Name = "getBtn"
Me.getBtn.TabIndex = 14
Me.getBtn.Text = "Get"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(616, 374)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.getBtn,
Me.dropBtn, Me.lookBtn, Me.useBtn, Me.talkBtn, Me.Button4, Me.Button3,
Me.Button2, Me.Button1, Me.Label3, Me.Label2, Me.itemsList,
Me.inventoryList, Me.mainLbl})
Me.Name = "Form1"
Me.Text = "Gravel Ridge Adventure 0.0"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles useBtn.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
mainLbl.Text = "Welcome To Gravel Ridge Adventure"
Dim lecroneLivingRoom As New room()
lecroneLivingRoom.desc = "You are in the Lecrone Living Room"
mainLbl.Text = mainLbl.Text & lecroneLivingRoom.desc
wigwamexists = True
If wigwamexists = True Then
mainLbl.Text = mainLbl.Text & "There is a Wigwam here."
itemsList.Items.Add("wigwam")
End If
End Sub
Private Sub itemsList_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles itemsList.SelectedIndexChanged
End Sub
Private Sub inventoryList_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
inventoryList.SelectedIndexChanged
End Sub
Private Sub lookBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lookBtn.Click
If itemsList.SelectedItem = "wigwam" Then
mainLbl.Text = mainLbl.Text & "This is a superhero jacket"
End If
End Sub
Private Sub dropBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles dropBtn.Click
End Sub
Private Sub getBtn_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles getBtn.Click
If currentLocation = "livingRoom" And wigwamexists = True Then
itemsList.SelectedItem = "wigwam"
inventoryList.Items.Add("wigwam")
itemsList.Items.Remove("wigwam")
wigwamexists = False
End If
End Sub
End Class 2 1240
I think I may have figured it out. I have a class and dim conflict with the
IF currentlocation strong.
"Brian" <br***********@yahoo.com> wrote in message
news:OB**************@TK2MSFTNGP12.phx.gbl... I am very new to VB.NET and I just need some help in a listbox matter. I don't need suggestions on how to make the overall code better. I will get there.
I want to move an item from one list box to another should it be selected
in combination with a button click and selected. I've got the code in there
but it just wont work. Below is the entire code but I only need help with the following items:
getBtn inventoryList itemsList
This is a simple text adventure that I am starting. I just need to know
why the item wont appear in inventoryList when the proper item is selected in itemsList and the getBtn is used.
Thanks!
Public Class Form1
Inherits System.Windows.Forms.Form
Dim currentLocation As String
Dim livingRoomDesc As String
Dim wigwamexists As Boolean #Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents mainLbl As System.Windows.Forms.Label
Friend WithEvents itemsList As System.Windows.Forms.ListBox
Friend WithEvents inventoryList As System.Windows.Forms.ListBox
Friend WithEvents lookBtn As System.Windows.Forms.Button
Friend WithEvents dropBtn As System.Windows.Forms.Button
Friend WithEvents talkBtn As System.Windows.Forms.Button
Friend WithEvents useBtn As System.Windows.Forms.Button
Friend WithEvents getBtn As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent() Me.mainLbl = New System.Windows.Forms.Label()
Me.inventoryList = New System.Windows.Forms.ListBox()
Me.itemsList = New System.Windows.Forms.ListBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.Button4 = New System.Windows.Forms.Button()
Me.talkBtn = New System.Windows.Forms.Button()
Me.useBtn = New System.Windows.Forms.Button()
Me.lookBtn = New System.Windows.Forms.Button()
Me.dropBtn = New System.Windows.Forms.Button()
Me.getBtn = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'mainLbl
'
Me.mainLbl.Location = New System.Drawing.Point(8, 8)
Me.mainLbl.Name = "mainLbl"
Me.mainLbl.Size = New System.Drawing.Size(448, 136)
Me.mainLbl.TabIndex = 0
'
'inventoryList
'
Me.inventoryList.Location = New System.Drawing.Point(480, 32)
Me.inventoryList.Name = "inventoryList"
Me.inventoryList.Size = New System.Drawing.Size(128, 121)
Me.inventoryList.TabIndex = 1
'
'itemsList
'
Me.itemsList.Location = New System.Drawing.Point(480, 200)
Me.itemsList.Name = "itemsList"
Me.itemsList.Size = New System.Drawing.Size(128, 121)
Me.itemsList.TabIndex = 2
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(480, 8)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(128, 16)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Inventory"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(480, 160)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(128, 24)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Objects / Persons in Room"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(208, 176)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 5
Me.Button1.Text = "North"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(136, 200)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 6
Me.Button2.Text = "West"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(208, 224)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 7
Me.Button3.Text = "South"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(280, 200)
Me.Button4.Name = "Button4"
Me.Button4.TabIndex = 8
Me.Button4.Text = "East"
'
'talkBtn
'
Me.talkBtn.Location = New System.Drawing.Point(176, 288)
Me.talkBtn.Name = "talkBtn"
Me.talkBtn.TabIndex = 9
Me.talkBtn.Text = "Talk"
'
'useBtn
'
Me.useBtn.Location = New System.Drawing.Point(88, 288)
Me.useBtn.Name = "useBtn"
Me.useBtn.TabIndex = 10
Me.useBtn.Text = "Use"
'
'lookBtn
'
Me.lookBtn.Location = New System.Drawing.Point(0, 288)
Me.lookBtn.Name = "lookBtn"
Me.lookBtn.TabIndex = 11
Me.lookBtn.Text = "Look"
'
'dropBtn
'
Me.dropBtn.Location = New System.Drawing.Point(352, 288)
Me.dropBtn.Name = "dropBtn"
Me.dropBtn.TabIndex = 12
Me.dropBtn.Text = "Drop"
'
'getBtn
'
Me.getBtn.Location = New System.Drawing.Point(264, 288)
Me.getBtn.Name = "getBtn"
Me.getBtn.TabIndex = 14
Me.getBtn.Text = "Get"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(616, 374)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.getBtn, Me.dropBtn, Me.lookBtn, Me.useBtn, Me.talkBtn, Me.Button4, Me.Button3, Me.Button2, Me.Button1, Me.Label3, Me.Label2, Me.itemsList, Me.inventoryList, Me.mainLbl})
Me.Name = "Form1"
Me.Text = "Gravel Ridge Adventure 0.0"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles useBtn.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mainLbl.Text = "Welcome To Gravel Ridge Adventure"
Dim lecroneLivingRoom As New room()
lecroneLivingRoom.desc = "You are in the Lecrone Living Room"
mainLbl.Text = mainLbl.Text & lecroneLivingRoom.desc
wigwamexists = True
If wigwamexists = True Then
mainLbl.Text = mainLbl.Text & "There is a Wigwam here."
itemsList.Items.Add("wigwam")
End If
End Sub
Private Sub itemsList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles itemsList.SelectedIndexChanged
End Sub
Private Sub inventoryList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles inventoryList.SelectedIndexChanged
End Sub
Private Sub lookBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lookBtn.Click
If itemsList.SelectedItem = "wigwam" Then
mainLbl.Text = mainLbl.Text & "This is a superhero jacket"
End If
End Sub
Private Sub dropBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dropBtn.Click
End Sub
Private Sub getBtn_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles getBtn.Click
If currentLocation = "livingRoom" And wigwamexists = True Then
itemsList.SelectedItem = "wigwam"
inventoryList.Items.Add("wigwam")
itemsList.Items.Remove("wigwam")
wigwamexists = False
End If
End Sub
End Class
* "Brian" <br***********@yahoo.com> scripsit: I am very new to VB.NET and I just need some help in a listbox matter. I don't need suggestions on how to make the overall code better. I will get there.
I want to move an item from one list box to another should it be selected in combination with a button click and selected. I've got the code in there but it just wont work. Below is the entire code but I only need help with the following items:
\\\
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Add the item to the 2nd listbox.
Me.ListBox2.Items.Add(Me.ListBox1.SelectedItem)
' Remove it from the 1st listbox.
Me.ListBox1.Items.Remove(Me.ListBox1.SelectedItem)
End Sub
///
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: KinŽsole |
last post by:
Hi
I'm very new to VB (using VB6)
I have two lists one blank and one containing names in the format of surname
and then forename.I also have a combo box containing forenames.When I
select a...
|
by: python-help-bounces |
last post by:
Your message for python-help@python.org, the Python programming
language assistance line, has been received and is being delivered.
This automated response is sent to those of you new to...
|
by: Brian van den Broek |
last post by:
Hi all,
There have been a few posts over the last month or so expressing a bit
of exasperation with the "rising tide of newbie's". (Or, more
accurately, the rising tide of questions from...
|
by: Shawn Windle |
last post by:
----begin node.h--------
#ifndef NODE_H
#define NODE_H
#include <iostream> //NULL
using namespace std;
class node
{
|
by: Enterprise |
last post by:
Hi,
I'm useing Access 2000. I have an alphabetized list box in a form. Is there
an easy way to have the list box go to a certain letter in the list? Like if
I'm in the list box, and I type m, I...
|
by: John N. |
last post by:
Hi All,
Here I have a linked list each containing a char and is double linked.
Then I have a pointer to an item in that list which is the current
insertion point.
In this funtion, the user...
|
by: Michael Rockwell |
last post by:
I am new to using C# generics and I am liking what I am finding. However the
examples in online help are lacking. Can someone help me with the FindAll
method of the generic List class? As I...
|
by: Cox |
last post by:
Hello:
My address jsmith435@cox.net is subscribed to at least the PHP General
mailing list. I have for days now been trying to unsubscribe from all PHP
mail lists. I have followed the...
|
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 {
|
by: NatsoumiMaya |
last post by:
hi ppl,
i have a code to write in C where i have to implement the mkdir, rm, rmdir and touch functions using double linked lists...im haveing trouble with it...here is what i have so far:
#ifndef...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
| |