vb.net - Add items from a collection to a combo box -
i have class reads text file, , adds collection. i'm trying figure out how read collection populate combobox upon loading of program.
billingdata class
public readonly property clients collection homecoming mclients end end property sub new() mclientfile = opentext("clients.txt") dim mclients new collection while not mclientfile.endofstream mclients.add(mclientfile.readline()) end while mclientfile.close()
mainform
private sub frmmain_load(sender object, e eventargs) handles mybase.load client = new billingdata() dim integer while < client.clients.count cbclient.items.addrange(client.clients(i)) = + 1 end while end sub
i made 3 changes frmmain_load
subroutine.
i
1. changed while loop status <=
. used add
instead of addrange
.
private sub frmmain_load(sender object, e eventargs) handles mybase.load client = new billingdata() dim integer = 1 while <= client.clients.count cbclient.items.add(client.clients(i)) = + 1 end while end sub
an interesting thing note first alter (initializing 1): value of clients @ index 0 "empty placeholder 1-based array". means collection starts @ index 1. code sort of throw phantom exception never gets caught - typical in vb.net form load routines. can test out setting breakpoint in load code , see never gets line i = + 1
. if placed code in button click event instead, see code break on exception. moral of story careful on code set on form load routines, because not immediate feedback if there bug in code.
vb.net class collections combobox
No comments:
Post a Comment