Trouble getting list box items to populate in C# -
i need call array following program working, can't figure out. i'm not sure or isn't working, because can't list box populate. following code.
using system.io; namespace test_your_knowledge__game { public partial class form1 : form { public form1() { initializecomponent(); } string questionone; string questiontwo; string questionthree; string firstquestion = ("who silk worm?"); string secondquestion = ("what sapience mean?"); string thirdquestion = ("what tainou?"); string firstanswer = ("onycho"); string secondanswer = ("wisdom"); string thirdanswer = ("a wolf"); int count = 0; private void listbox1_selectedindexchanged(object sender, eventargs e) { } private void playbutton_click(object sender, eventargs e) { string name; string email; name = nametextbox.text; email = emailtextbox.text; streamwriter outputfile; outputfile = file.createtext("submission_list.txt"); outputfile.writeline(name); outputfile.writeline(email); outputfile.writeline(count); outputfile.close(); } private void myarray(string[] strarray, string value) { bool found = false; int index = 0; int position = -1; while (!found && index < strarray.length) if (strarray[index] == value) { found = true; position = index; index++; } string[] questiononearray = { "1) beebo", "2) bael", "3) onycho", "4) ilion" }; string[] questiontwoarray = { "1) beauty", "2) cursed", "3) properity", "4) wisdom" }; string[] questionthreearray = { "1) imp", "2) wolf", "3) trow", "4) elf" }; foreach (string length in strarray) { try { if (questiononearray[index] != firstanswer) { questionone = (firstquestion + "" + questiononearray); listbox1.items.add(questionone.tostring()); found = false; } else { found = true; count++; } { if (questiontwoarray[index] != secondanswer) { questiontwo = (secondquestion + "" + questiontwoarray); listbox1.items.add(questiontwo.tostring()); found = false; } else { found = true; count++; } { if (questionthreearray[index] != thirdanswer) { questionthree = (thirdquestion + "" + questionthreearray); listbox1.items.add(questionthree.tostring()); found = false; } else { found = true; count++; } } } } catch (exception) { } } } }
all have use datasource
property
public partial class form1 : form { public form1() { initializecomponent(); } protected override void onload(eventargs e) { base.onload(e); string[] questions=new string[] { "who silk worm?", "what sapience mean?", "what tainou?" }; listbox1.datasource=questions; } }
alternatively can read file
list<string> questions=new list<string>(); var fs=file.opentext("<path file questions here>"); while (fs.endofstream) { questions.add(fs.readline()); } fs.close(); listbox1.datasource=questions;
Comments
Post a Comment