vb.net - I want to know how to add items to an arraylist -
here code:-
if firstnametext.text = "" messagebox.show("please enter first name please") end if if surnametext.text = "" messagebox.show("please enter surname please") end if if (not rb_male.checked) andalso (not rb_female.checked) messagebox.show("please select gender") end if if combobox1.selectedvalue = false messagebox.show("please select year group") end if if textstudentid.text = "" messagebox.show("please select generate button give unique student id") end if "in section want add submitted items arraylist user's name pops in list box" try catch ex exception end try
that's bit of code have written , have looked everywhere answer submit items arraylist. " " area i'm planning submit items arraylist. or link guide do.
first, make class student information
class student public firstname string public surname string public gender string public yeargroup string public studentid string end class
second, use list
not arraylist
, , make sure @ class level can used throughout code
private studentlist new list(of student)
third, after validate data controls on form, instantiate student
object , add studentlist
. once you're done adding new student
data, can access studentlist
in other methods whatever want
' validate fields have data new student if string.isnullorempty(firstnametext.text) messagebox.show("please enter first name please") firstnametext.focus() return elseif string.isnullorempty(surnametext.text) messagebox.show("please enter surname please") surnametext.focus() return elseif not rb_male.checked andalso not rb_female.checked messagebox.show("please select gender") return elseif combobox1.selectedindex = -1 messagebox.show("please select year group") return elseif string.isnullorempty(textstudentid.text) messagebox.show("please select generate button give unique student id") generatebutton.focus() return end if ' create new student object dim newstudent new student() newstudent.firstname = firstnametext.text newstudent.surname = surnametext.text if rb_male.checked newstudent.gender = "m" else newstudent.gender = "f" end if newstudent.yeargroup = combobox1.selecteditem newstudent.studentid = textstudentid.text ' add new student object list studentlist.add(newstudent)
Comments
Post a Comment