vb.net - Adding Selected Item in a Listbox to a Label in Visual Basic -


in program i'm writing i'm stuck on 1 of last steps display employee's name , salary selected listbox in labels (one name , 1 salary), cannot figure out how this. employee's names , salaries read in file , placed in corresponding listboxes on 3 different forms (two list names, , 1 lists salaries). on last form, user supposed select name of 1 of employees , person's name supposed appear in 1 label (lblname) , salary supposed appear in label (lblsalary). names listed in selectable listbox, when click on 1 of them nothing happens.

here code have far on main form:

option strict on imports system.io  public class main  private sub open_click(sender object, e eventargs) handles open.click     dim open new openfiledialog     open.filter = "text files |*.txt|all files|*.*"     open.initialdirectory = environment.getfolderpath(environment.specialfolder.desktopdirectory)      if open.showdialog() = windows.forms.dialogresult.ok         dim selectedfilename string = system.io.path.getfilename(open.filename)         shownames.enabled = true         showsalaries.enabled = true         showemployee.enabled = true     end if      dim container new list(of project9)     using reader new streamreader(open.openfile)         while not reader.endofstream             dim employee new project9             employee.name = reader.readline()             employee.salary = cdbl(reader.readline())             container.add(employee)         end while     end using      each item project9 in container         names.lstnames.items.add(item.name)         frmtotal.lstshow.items.add(item.name)         salaries.lstsalaries.items.add(item.salary)     next  end sub  private sub exittoolstripmenuitem_click(sender object, e eventargs) handles exittoolstripmenuitem.click     me.close()     names.close()     salaries.close()     frmtotal.close() end sub  private sub shownames_click(sender object, e eventargs) handles shownames.click     names.show() end sub  private sub showsalaries_click(sender object, e eventargs) handles showsalaries.click     salaries.show() end sub  private sub showemployee_click(sender object, e eventargs) handles showemployee.click     frmtotal.show() end sub end class  public class project9  dim strname string dim dblsalary double  public property name string             return strname     end     set(value string)         strname = value     end set end property  public property salary double             return dblsalary     end     set(value double)         if dblsalary < 0             dblsalary = 10         end if         dblsalary = value     end set  end property   public function computesalary(intmonths integer) double     dim dbltotal double = dblsalary * intmonths      return dbltotal end function  end class 

and here's code 4th form 1 displaying selected item in labels:

public class frmtotal  private sub btncalculate_click(sender object, e eventargs) handles btncalculate.click      lblname.text = lstshow.selecteditem(name)      dim intmonths integer     intmonths = inputbox("how many months calculate employee's salary for?")  end sub end class 

also, how able make button visible after item has been selected?

any appreciated.

if leverage datasource property of listbox can fill listbox project9 items , use displaymember property choose property display in listbox. has several advantages. whenever listbox item selected can cast object of type project9 , can display whichever properties want labels. selection tied across listboxes selection in 1 same selection in others. here's example of how might look:

dim employees new list(of project9)(     {         new project9 {.name = "a", .salary = 1000},         new project9 {.name = "b", .salary = 1200},         new project9 {.name = "c", .salary = 1100}         }) listbox1.datasource = employees listbox1.displaymember = "name" listbox2.datasource = employees listbox2.displaymember = "salary"   private sub listbox1_selectedindexchanged(sender object, e eventargs) handles listbox1.selectedindexchanged     dim selectedemployee = directcast(listbox1.selecteditem, project9)     label1.text = selectedemployee.name     label2.text = selectedemployee.salary.tostring end sub 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -