c# - How to reload a form -
i have looking solution still found nothing
here code:
private void form1_load(object sender, eventargs e) { richtextbox rtb = new richtextbox(); rtb.text = file.readalltext(@"c:\users\admin\desktop\myfile\customers.txt"); int = 0; foreach (string line in rtb.lines) { if (line == "--") { listviewitem item = new listviewitem(); item.text = rtb.lines[i + 1]; item.subitems.add(rtb.lines[i + 2]); item.subitems.add(rtb.lines[i + 3]); item.subitems.add(rtb.lines[i + 4]); listview1.items.add(item); } += 1; } } private void button1_click(object sender, eventargs e) { form2 pop = new form2(); pop.showdialog(); string name = pop.name; int age = int.parse(pop.age); string dob = pop.dateofbirth; string addr = pop.address; streamwriter write = new streamwriter(@"c:\users\admin\desktop\myfile\customers.txt",true); write.write("--\n"); write.write("{0}\n",name); write.write("{0}\n",dob); write.write("{0}\n",age); write.write("{0}\n",addr); write.close(); }
the question how reload list view after write data text file?
extract logic out of form1_load
private void form1_load(object sender, eventargs e) { refreshlistview(); } private void button1_click(object sender, eventargs e) { form2 pop = new form2(); pop.showdialog(); string name = pop.name; int age = int.parse(pop.age); string dob = pop.dateofbirth; string addr = pop.address; streamwriter write = new streamwriter(@"c:\users\admin\desktop\myfile\customers.txt",true); write.write("--\n"); write.write("{0}\n",name); write.write("{0}\n",dob); write.write("{0}\n",age); write.write("{0}\n",addr); write.close(); refreshlistview(); } private void refreshlistview() { listview1.items.clear(); richtextbox rtb = new richtextbox(); rtb.text = file.readalltext(@"c:\users\admin\desktop\myfile\customers.txt"); int = 0; foreach (string line in rtb.lines) { if (line == "--") { listviewitem item = new listviewitem(); item.text = rtb.lines[i + 1]; item.subitems.add(rtb.lines[i + 2]); item.subitems.add(rtb.lines[i + 3]); item.subitems.add(rtb.lines[i + 4]); listview1.items.add(item); } += 1; } }
Comments
Post a Comment