Code advice For list selection

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2008
Posts: 11
Reputation: wrichardson530 is an unknown quantity at this point 
Solved Threads: 0
wrichardson530 wrichardson530 is offline Offline
Newbie Poster

Code advice For list selection

 
0
  #1
May 1st, 2008
PosOfSpace = InString(LstStudent.Value, 1, " ")

txtStudentId.Text = Mid(LstStudent.Value, 1, PosOfType - 1)


I'm tring to get the studentId to show up in the StudentId text box. This is supposed to be done by double clicking on the student you want process This is in the list called LstStudent.

This code is in a double clilck event on a list box.

the bolded part of code is where i'm encoutnering my error

its a comple erroe saying method or datamember not found.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 520
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 89
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: Code advice For list selection

 
0
  #2
May 1st, 2008
Hi
ListBoxes dont have Value property. Instead
Text Property to get the selected Text
Ex
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. MsgBox LstStudent.Text

ListIndex property is used to get the current selected Item Index. If none of the item is selected it has -1 value

List() Property contains all the Items like array
U can use similar to the above using ListIndex
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. MsgBox LstStudent.List(LstStudent.ListIndex)

Text Property is not apt for multiple selection. At that situation use the above method
Your Corrected code
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ' Check whether anything selected
  2. If LstStudent.ListIndex >= 0 Then<blockquote>
  3. PosOfSpace = InStr ( LstStudent.List ( LstStudent.ListIndex ) , 1, " " )
  4. txtStudentId.Text = Mid ( LstStudent.List ( LstStudent.ListIndex ) , 1, PosOfType - 1)</blockquote>else<blockquote>
  5. ' Nothing selected
  6. MsgBox "Please Select anything"</blockquote>End If
Last edited by selvaganapathy; May 1st, 2008 at 12:38 pm.
Selva
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 752 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC