C# how to load listview -



C# how to load listview -

im doing windows form application open , load database. code needs show single record view of records , listview view stuck on listview part.

here next code

using system; using system.io; using system.collections.generic; using system.componentmodel; using system.data; using system.data.oledb; using system.drawing; using system.linq; using system.text; using system.windows.forms; using adox; namespace ex3 { public partial class changebutton : form { public list<client> clientrecords = new list<client>(); //creates list records stored public string filename; public string filedir; public string rec; public bool checkbc; public bool checklc; public string databasefile; public oledbconnection conn; public changebutton() { initializecomponent(); } int position = 0; private void form1_load(object sender, eventargs e) { credbalbox.maximum = 9999999999; savingbalbox.maximum = 9999999999; } private void connecttodatabase() { seek { string strconn = @"provider=microsoft.jet.oledb.4.0;data source=" + databasefile + ";"; conn = new oledbconnection(strconn); conn.open(); } grab (oledbexception e) { messagebox.show("failed connect database: " + e.message); } } private void nextbutton_click(object sender, eventargs e) { if (position < clientrecords.count - 1) { position++; print(); } else { messagebox.show("outside of record limit"); } } private void previousbutton_click(object sender, eventargs e) { if (position > 0) { position--; print(); } else { messagebox.show("outside of record limit"); } } public void print() { int positionadd1; positionadd1 = position; positionadd1++; currentreclab.text = positionadd1.tostring(); maxreclab.text = clientrecords.count.tostring(); if (position >= 0 && position < clientrecords.count) { namebox.text = clientrecords[position].name; suburbbox.text = clientrecords[position].suburb; postbox.text = clientrecords[position].postcode; credbalbox.text = clientrecords[position].creditbal.tostring(); savingbalbox.text = clientrecords[position].savingbal.tostring(); } else { namebox.text = ""; suburbbox.text = ""; postbox.text = ""; credbalbox.text = ""; savingbalbox.text = ""; } } private void addbutton_click(object sender, eventargs e) { string sameaddname = "null"; string addname; string addsuburb; string addpostcode; decimal addcredbal; decimal addsavbal; addname = namebox.text; addsuburb = suburbbox.text; addpostcode = postbox.text; addcredbal = decimal.parse(credbalbox.text); addsavbal = decimal.parse(savingbalbox.text); string sqlprefix = "insert client values "; string info = "(" + "'" + addname + "','" + addsuburb + "','" + addpostcode + "','" + addcredbal + "','" + addsavbal + "'" + ")"; string sql = sqlprefix + data; foreach (client client in clientrecords) { if (addname == client.name) { sameaddname = "name not unique. please utilize unique name"; } } if (sameaddname == "null" && addsuburb != null) { clientrecords.add(new client(addname, addsuburb, addpostcode, addcredbal, addsavbal)); oledbcommand cmd = new oledbcommand(sql, conn); cmd.executenonquery(); int positions = clientrecords.count; currentreclab.text = positions.tostring(); maxreclab.text = positions.tostring(); namebox.text = addname; suburbbox.text = addsuburb; postbox.text = addpostcode; credbalbox.text = addcredbal.tostring(); savingbalbox.text = addsavbal.tostring(); position = clientrecords.count - 1; } else { if ((sameaddname != "null") && (addsuburb == "") && (addpostcode == "")) { messagebox.show(sameaddname + "\nalso, 1 of fields empty. please fill in before adding new record"); } else if (sameaddname != "null") { messagebox.show(sameaddname); } } } private void removebutton_click(object sender, eventargs e) { int recposition = int.parse(currentreclab.text); recposition = recposition - 1; position = 0; clientrecords.remove(clientrecords[recposition]); print(); if (maxreclab.text == "0") { currentreclab.text = "0"; } } private void loadbutton_click_1(object sender, eventargs e) { oledbcommand cmd = new oledbcommand ("select * client", conn); using (oledbdatareader rdr = cmd.executereader()) { while (rdr.read()) { client nclient = new client(rdr[0].tostring(), rdr[1].tostring(), rdr[2].tostring(), decimal.parse(rdr[3].tostring()), decimal.parse(rdr[4].tostring())); clientrecords.add(nclient); print(); } } } private void connectbutton_click(object sender, eventargs e) { openfiledialog dialog = new openfiledialog(); dialog.title = "select database"; if (dialog.showdialog() == dialogresult.ok) { databasefile = dialog.filename; databasenamebox.text = databasefile; connecttodatabase(); } } private void databasenamebox_textchanged(object sender, eventargs e) { } private void label7_click(object sender, eventargs e) { } private void namebox_textchanged(object sender, eventargs e) { } private void listview1_selectedindexchanged(object sender, eventargs e) { } } public class client { protected string name; protected string suburb; protected string postcode; protected decimal creditbal; protected decimal savingbal; public client(string name, string suburb, string postcode, decimal creditbal, decimal savingbal) { this.name = name; this.suburb = suburb; this.postcode = postcode; this.creditbal = creditbal; this.savingbal = savingbal; } public string name { { homecoming name; } set { name = value; } } public string suburb { { homecoming suburb; } set { suburb = value; } } public string postcode { { homecoming postcode; } set { postcode = value; } } public decimal creditbal { { homecoming creditbal; } set { creditbal = value; } } public decimal savingbal { { homecoming savingbal; } set { savingbal = value; } } } }

thanks in advance

further info

private void listview1_selectedindexchanged(object sender, eventargs e) { }

i want able set code here , when click load button above should load listview

c#

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -