c# - How do you save selected ComboBox items into a .txt file -


hi i'm new programming , trying create c# grade calculator using wpf users enter grades , remove 2 of lowest grades , tell them overall grade, have got part working save selected grade comboboxes txt file , maybe able load txt file grade calculator again.

here code have far

<window x:class="gradecalculator.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="grade calculator" height="779.736" width="952"> <grid>     <grid.background>         <lineargradientbrush endpoint="0.5,1" startpoint="0.5,0">             <gradientstop color="white" offset="1"/>             <gradientstop color="#ffaef7f7"/>             <gradientstop color="#ffd0fafa" offset="0.49"/>         </lineargradientbrush>     </grid.background>     <menu verticalalignment="top" ismainmenu="true" margin="0,0,868,0"/>     <label name="title" content="grade calculator" margin="366,181,366,0" verticalalignment="top" fontsize="25" horizontalalignment="center" fontweight="bold" width="212"/>     <textblock name="information" horizontalalignment="center" margin="324,223,324,0" textwrapping="wrap" text="please enter grades or predicted grades drop down menus below" verticalalignment="top" width="296" fontsize="16" textalignment="center"/>     <label name="mandatory" content="mandatory units" horizontalalignment="left" margin="156,273,0,0" verticalalignment="top" height="28" width="122" fontsize="14" fontweight="bold"/>     <textblock name="ces" horizontalalignment="left" margin="12,306,0,0" textwrapping="wrap" verticalalignment="top" fontsize="16"><run text="communication , employability"/><linebreak/><run text="skills it"/></textblock>     <textblock name="cs" horizontalalignment="left" margin="12,354,0,0" textwrapping="wrap" text="computer systems" verticalalignment="top" fontsize="16"/>     <textblock name="is" horizontalalignment="left" margin="12,380,0,0" textwrapping="wrap" text="information systems" verticalalignment="top" fontsize="16"/>     <textblock name="sdd" horizontalalignment="left" margin="12,406,0,0" textwrapping="wrap" text="software design , development" verticalalignment="top" fontsize="16"/>     <textblock name="sad" horizontalalignment="left" margin="12,432,0,0" textwrapping="wrap" text="systems analysis , design" verticalalignment="top" fontsize="16"/>     <textblock name="edp" horizontalalignment="left" margin="10,462,0,0" textwrapping="wrap" text="event driven programming" verticalalignment="top" fontsize="16"/>     <combobox name="cesbox" horizontalalignment="left" margin="288,318,0,0" verticalalignment="top" width="120">         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="csbox" horizontalalignment="left" margin="288,354,0,0" verticalalignment="top" width="120">         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="isbox" horizontalalignment="left" margin="288,462,0,0" verticalalignment="top" width="120">         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="sddbox" horizontalalignment="left" margin="288,381,0,0" verticalalignment="top" width="120">         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="sadbox" horizontalalignment="left" margin="288,408,0,0" verticalalignment="top" width="120">         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="edpbox" horizontalalignment="left" margin="288,435,0,0" verticalalignment="top" width="120">         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <label name="optional" content="optional units" horizontalalignment="left" margin="644,273,0,0" verticalalignment="top" height="28" width="118" fontsize="14" fontweight="bold"/>     <textblock name="mn" horizontalalignment="left" margin="480,301,0,0" textwrapping="wrap" verticalalignment="top" fontsize="16"><run text="managing network"/><run text="s"/></textblock>     <textblock name="cn" horizontalalignment="left" margin="480,327,0,0" textwrapping="wrap" text="computer networks" verticalalignment="top" fontsize="16" height="22"/>     <textblock name="ct" horizontalalignment="left" margin="480,354,0,0" textwrapping="wrap" text="communication technologies" verticalalignment="top" fontsize="16" height="22"/>     <textblock name="itts" horizontalalignment="left" margin="480,381,0,0" textwrapping="wrap" text="it technical support" verticalalignment="top" fontsize="16" height="22"/>     <textblock name="ittstr" horizontalalignment="left" margin="480,408,0,0" textwrapping="wrap" text="it systems , troubleshooting , repair" verticalalignment="top" fontsize="16" height="22"/>     <textblock name="ppit" horizontalalignment="left" margin="480,435,0,0" textwrapping="wrap" text="project planning it" verticalalignment="top" fontsize="16" height="22"/>     <textblock name="db" horizontalalignment="left" margin="480,462,0,0" textwrapping="wrap" text="database design" verticalalignment="top" fontsize="16" height="22"/>     <textblock name="cscwp" horizontalalignment="left" margin="480,489,0,0" textwrapping="wrap" text="client side customisation of web pages" verticalalignment="top" fontsize="16" height="22"/>     <textblock name="dcg" horizontalalignment="left" margin="480,516,0,0" textwrapping="wrap" text="developing computer games" verticalalignment="top" fontsize="16" height="22"/>     <textblock name="wss" horizontalalignment="left" margin="480,543,0,0" textwrapping="wrap" text="web server scripting" verticalalignment="top" fontsize="16" height="22"/>     <textblock name="wp" horizontalalignment="left" margin="480,570,0,0" textwrapping="wrap" text="website production" verticalalignment="top" fontsize="16" height="22"/>     <textblock name="dg" horizontalalignment="left" margin="480,597,0,0" textwrapping="wrap" text="digital graphics" verticalalignment="top" fontsize="16" height="22"/>     <textblock name="nss" horizontalalignment="left" margin="480,624,0,0" textwrapping="wrap" verticalalignment="top" fontsize="16" height="22"><run text="network systems secur"/><run text="i"/><run text="ty"/></textblock>     <textblock name="waim" horizontalalignment="left" margin="480,651,0,0" textwrapping="wrap" verticalalignment="top" fontsize="16" height="22"><run text="web animation interactive med"/><run text="i"/><run text="a"/></textblock>     <combobox name="mnbox" horizontalalignment="left" margin="798,300,0,0" verticalalignment="top" width="120">         <comboboxitem content="fail" horizontalalignment="left" width="118"/>         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="cnbox" horizontalalignment="left" margin="798,327,0,0" verticalalignment="top" width="120">         <comboboxitem content="fail" horizontalalignment="left" width="118"/>         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="ctbox" horizontalalignment="left" margin="798,354,0,0" verticalalignment="top" width="120">         <comboboxitem content="fail" horizontalalignment="left" width="118"/>         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="ittsbox" horizontalalignment="left" margin="798,381,0,0" verticalalignment="top" width="120">         <comboboxitem content="fail" horizontalalignment="left" width="118"/>         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="ittstrbox" horizontalalignment="left" margin="798,408,0,0" verticalalignment="top" width="120">         <comboboxitem content="fail" horizontalalignment="left" width="118"/>         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="ppitbox" horizontalalignment="left" margin="798,435,0,0" verticalalignment="top" width="120">         <comboboxitem content="fail" horizontalalignment="left" width="118"/>         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="dbbox" horizontalalignment="left" margin="798,462,0,0" verticalalignment="top" width="120">         <comboboxitem content="fail" horizontalalignment="left" width="118"/>         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="cscwpbox" horizontalalignment="left" margin="798,489,0,0" verticalalignment="top" width="120">         <comboboxitem content="fail" horizontalalignment="left" width="118"/>         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="dcgbox" horizontalalignment="left" margin="798,516,0,0" verticalalignment="top" width="120">         <comboboxitem content="fail" horizontalalignment="left" width="118"/>         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="wssbox" horizontalalignment="left" margin="798,543,0,0" verticalalignment="top" width="120">         <comboboxitem content="fail" horizontalalignment="left" width="118"/>         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="wpbox" horizontalalignment="left" margin="798,570,0,0" verticalalignment="top" width="120">         <comboboxitem content="fail" horizontalalignment="left" width="118"/>         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="dgbox" horizontalalignment="left" margin="798,597,0,0" verticalalignment="top" width="120">         <comboboxitem content="fail" horizontalalignment="left" width="118"/>         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="nssbox" horizontalalignment="left" margin="798,624,0,0" verticalalignment="top" width="120">         <comboboxitem content="fail" horizontalalignment="left" width="118"/>         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <combobox name="waimbox" horizontalalignment="left" margin="798,651,0,0" verticalalignment="top" width="120">         <comboboxitem content="fail" horizontalalignment="left" width="118"/>         <comboboxitem content="pass" horizontalalignment="left" width="118"/>         <comboboxitem content="merit" horizontalalignment="left" width="118"/>         <comboboxitem content="distinction" horizontalalignment="left" width="118"/>     </combobox>     <button name="subbutton" content="submit" horizontalalignment="left" margin="396,686,0,0" verticalalignment="top" click="button_click" width="130" height="38" fontsize="18"/>     <image margin="324,0,298,541" source="bsdc.png" stretch="fill"/>     <label name="totalgrade" content="" horizontalalignment="left" margin="104,597,0,0" verticalalignment="top" height="49" width="225" fontsize="30"/>     <label name="totalscore" content="" horizontalalignment="left" margin="104,534,0,0" verticalalignment="top" height="49" width="225" fontsize="30"/>     <button name="savebutton" content="save grades" horizontalalignment="left" margin="12,10,0,0" verticalalignment="top" click="savebutt_click" width="75"/> </grid> 

    public mainwindow()     {         initializecomponent();     }      private void button_click(object sender, routedeventargs e)     {         int total = 0;          total += getgrade(cesbox);         total += getgrade(csbox);         total += getgrade(isbox);         total += getgrade(sddbox);         total += getgrade(sadbox);         total += getgrade(edpbox);         total += getgrade(mnbox);         total += getgrade(cnbox);         total += getgrade(ctbox);         total += getgrade(ittsbox);         total += getgrade(ittstrbox);         total += getgrade(ppitbox);         total += getgrade(dbbox);         total += getgrade(cscwpbox);         total += getgrade(dcgbox);         total += getgrade(wssbox);         total += getgrade(wpbox);         total += getgrade(dgbox);         total += getgrade(nssbox);         total += getgrade(waimbox);         total -= lowgrade1;         total -= lowgrade2;          if (total >= 1300 && total <= 1339)         {             grade = "mpp";         }         if (total >= 1340 && total <= 1379)         {             grade = "mmp";         }         if (total >= 1380 && total <= 1419)         {             grade = "mmm";         }         if (total >= 1420 && total <= 1459)         {             grade = "dmm";         }         if (total >= 1460 && total <= 1499)         {             grade = "ddm";         }         if (total >= 1500 && total <= 1529)         {             grade = "ddd";         }         if (total >= 1530 && total <= 1559)         {             grade = "d*dd";         }         if (total >= 1560 && total <= 1589)         {             grade = "d*d*d";         }         if (total >= 1590)         {             grade = "d*d*d*";         }          totalscore.content = "score = " + total;         totalgrade.content = "grade = " + grade;     }      public int getgrade(combobox cbcontent)     {         int score = 0;          comboboxitem cbcontentselecteditem = cbcontent.selecteditem comboboxitem;         if (cbcontentselecteditem != null)         {             if ((string)cbcontentselecteditem.content == "fail")             {                 if (lowgrade1 > 0)                 {                     lowgrade1 = 0;                 }                 else if (lowgrade2 > 0)                 {                     lowgrade2 = 0;                 }                 score = 0;             }             if ((string)cbcontentselecteditem.content == "pass")             {                 if (lowgrade1 > 70)                 {                     lowgrade1 = 70;                 }                 else if (lowgrade2 > 70)                 {                     lowgrade2 = 70;                 }                 score = 70;             }             if ((string)cbcontentselecteditem.content == "merit")             {                 if (lowgrade1 > 80)                 {                     lowgrade1 = 80;                 }                 else if (lowgrade2 > 80)                 {                     lowgrade2 = 80;                 }                 score = 80;             }             if ((string)cbcontentselecteditem.content == "distinction")             {                 if (lowgrade1 > 90)                 {                     lowgrade1 = 90;                 }                 else if (lowgrade2 > 90)                 {                     lowgrade2 = 90;                 }                 score = 90;             }         }         return score;     }      private void savebutt_click(object sender, routedeventargs e)     {      } } 

}

if have problem accessing c:\ app have problem of permission.

try creating new folder "c:\test" , try write there. or start visual studio administrator. include filename

public partial class mainwindow : window  {      public mainwindow()      {            initializecomponent();      }      private void savebutt_click(object sender, routedeventargs e)      {                      file.writealltext("c:\\file.txt", "hello world!");      }  } 

also check link more info


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -