c# - Create Save And Load Functionality For A Winform -
i have winform 5 text boxes , 2 data grids. need way of being able press button (or adding menu @ top file button , select save there) , save of values file user selects location/name for. need button (or again menu option) load file saved , values "save" generated on screen looks if input values.
how achieved in vs2017?
you describe problem , answer already. can straight forward implement that: save data file, when press button 2
, load data file form.
other approach, can have global variable, when press button 1
, save data variable, when button 2
pressed, load variable's value form.
public class userdata { public string location { get; set; } public string name { get; set; } }
then in form:
public partial class form1 : form { static list<userdata> saveddata; public form1() { initializecomponent(); saveddata = new list<userdata>(); } private void button1_click(object sender, eventargs e) { //this example only, data save saveddata.add(new userdata { location = "us", name = "boston" }); saveddata.add(new userdata { location = "us", name = "texas" }); } private void button2_click(object sender, eventargs e) { //this example only, write own business here foreach (var item in saveddata) { label1.text = item.location; label2.text = item.name; } } }
Comments
Post a Comment