What code to type to select item in listbox making its price appear in textbox? If and else statement | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What code to type to select item in listbox making its price appear in textbox? If and else statement

Windows form application

13th Dec 2017, 12:19 PM
Vishwadev Luchmun
Vishwadev Luchmun - avatar
2 Answers
0
use valuemember and displaymember http://www.tek-tips.com/viewthread.cfm?qid=778322 Fill your listbox with values ArrayList Provinces = new ArrayList() ; Provinces.Add(new Province("Alberta", "AB")); Provinces.Add(new Province("Columbie Britanique", "CB")) ; Provinces.Add(new Province("Quebec", "Qc")); Provinces.Add(new Province("Ontario", "ON")) ; Provinces.Add(new Province("Manitoba", "MN")); listBox1.DataSource = Provinces ; listBox1.DisplayMember = "LongName" ; listBox1.ValueMember = "ShortName" ; Get the selected value if (listBox1.SelectedIndex != -1) { textBox1.Text = listBox1.SelectedValue.ToString(); }
15th Dec 2017, 9:31 PM
sneeze
sneeze - avatar
0
thanks
13th Jan 2018, 7:06 AM
Vishwadev Luchmun
Vishwadev Luchmun - avatar