vb.net - Tying ComboBox/NumericUpDown selections to an array? -
i'm working on vb project has lot of comboboxes , numericupdown items.
lets have combobox1, 2, 3, 4, , 5; , have numericupdown1, 2, 3, 4, 5.
when user clicks "save" button, want save of selected combobox items , numericupdown numbers csv file. there elegant/automatic way tie of .selectedindex , .value these items array can write array out csv?
the way know far manually associate each 1 array position:
arr(0) = combobox1.selectedindex arr(1) = combobox2.selectedindex ... arr(5) = numericupdown1.value arr(6) = numericupdown2.value ... etc.
this wouldnt bad, except have lot of these items, , writing line each 1 seems silly. i'm new vb, might obvious solution some. ideas?
having them bound array handy because allow user load csv file, automatically populate comboboxes , numericupdowns csv values. way know manually move each array item respective combobox/numeric item when click load file button:
combobox1.selectedindex = arr(0) combobox2.selectedindex = arr(1) ... numericupdown1.value = arr(5) numericupdown2.value = arr(6) ... etc.
edit: here application info requested...
the csv file can saved/loaded looks this:
#"device info","123456","asdfgh","0000","1.0x","1" 000f,0000,0032,0000,00c8,0001,0078,0101,0000,0001,0000,0001 010f,0078,0000,0103,0001,0000,000a,0005,0007,0006,0000 0001,000a,000a,000a,000a,0005,0005,0005,0002 ...etc
the header line has serial number, version, , other misc info; automatically generated target device. of other lines configuration setpoints target device reads in , automatically configures itself. i'm writing pc program able edit (and create scratch) these configuration csv files nice gui interface. each item tied specific setpoint, such 000f = language, 0032 = system frequency, 00c8 = system voltage, etc. easiest way saw make configuration program use numeric entry , drop-down comboboxes user can select want. each nud , cbox equates 1 of csv file data fields.
you can use controls.find() reference desired control based on index value. here's quick example demonstrate mean:
for integer = 1 30 dim matches() control = me.controls.find("numericupdown" & i, true) if matches.length > 0 andalso typeof matches(0) numericupdown directcast(matches(0), numericupdown).value = end if next
you can incorporate code load/save routines.
Comments
Post a Comment