Ejemplo n.º 1
0
        private void ÖppnaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult result = dlgOpen.ShowDialog();

            if (result == DialogResult.OK)
            {
                dgView.Rows.Clear();
                FileStream inStream = new FileStream(dlgOpen.FileName, FileMode.Open, FileAccess.Read);

                BinaryReader reader = new BinaryReader(inStream);

                int antal = reader.ReadInt32();
                for (int i = 0; i < antal; i++)
                {
                    string ingrident = reader.ReadString();
                    float  mangd     = reader.ReadSingle();
                    string matt      = reader.ReadString();

                    Ingridiens I = new Ingridiens(ingrident, mangd, matt);
                    Ingridienser.Add(I);


                    dgView.Rows.Add(ingrident, mangd, matt);
                    dgView.Rows[dgView.Rows.Count - 1].Tag = I;
                }

                reader.Dispose();
            }
        }
Ejemplo n.º 2
0
 private void BtnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         Ingridiens I = new Ingridiens(tbxName.Text, float.Parse(tbxMangd.Text), tbxMatt.Text);
         Ingridienser.Add(I);
         dgView.Rows.Add(I.Name, I.Mangd, I.Matt);
         dgView.Rows[dgView.Rows.Count - 1].Tag = I;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Går inte att lägga in dina värden");
     }
 }