top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I add new item from other form to Xml file using c# form programming?

+1 vote
381 views

If write this code in form 1 :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml.Serialization;

namespace PostLab5_**********
{
    public partial class Form1 : Form
    {
        List<StudentInfo> Stu_Info = new List<StudentInfo>();
        Queue<StudentInfo> pass = new Queue<StudentInfo>();
        Queue<StudentInfo> fail = new Queue<StudentInfo>();
        Stack<StudentInfo> Excelent = new Stack<StudentInfo>();
        Stack<StudentInfo> VeryGood = new Stack<StudentInfo>();
        Stack<StudentInfo> Good = new Stack<StudentInfo>();
        public Form1()
        {
            InitializeComponent();
        }

        private void importXMLToolStripMenuItem_Click(object sender, EventArgs e)
        {

            OpenFileDialog Dlg = new OpenFileDialog();
            Dlg.Filter = "XML File|*.xml";
            if (Dlg.ShowDialog() == DialogResult.OK)
            {
                StreamReader Infile = new StreamReader(Dlg.FileName);
                XmlSerializer Des = new XmlSerializer(typeof(List<StudentInfo>));
                Stu_Info = (List<StudentInfo>)Des.Deserialize(Infile);
                Infile.Close();
                dataGridView1.DataSource = Stu_Info;
            }
        }

        private void passedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var R = from Item in Stu_Info
                    where Item.total >= 50
                    select Item;
            dataGridView1.DataSource = R.ToArray();
            foreach (StudentInfo item in R)
            {
                pass.Enqueue(item);
            }
        }

        private void failedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var R = from Item in Stu_Info
                    where Item.total < 50
                    select Item;
            dataGridView1.DataSource = R.ToArray();
            foreach (StudentInfo item in R)
            {
                fail.Enqueue(item);
            }
        }

        private void excellentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var R = from Item in Stu_Info
                    where Item.total >= 84
                    select Item;
            dataGridView1.DataSource = R.ToArray();
            foreach (StudentInfo Item in R)
            {
                Excelent.Push(Item);
            }
        }

        private void veryGoodToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var R = from Item in Stu_Info
                        where Item.total >=76 && Item.total <84
                        select Item;
                dataGridView1.DataSource = R.ToArray();
                foreach (StudentInfo Item in R)
                {
                    VeryGood.Push(Item);
                }
            }

        private void goodToolStripMenuItem_Click(object sender, EventArgs e)
        {
             var R = from Item in Stu_Info
                        where Item.total >= 68 && Item.total < 76
                        select Item;
                dataGridView1.DataSource = R.ToArray();
                foreach (StudentInfo Item in R)
                {
                    Good.Push(Item);
                }
        }

        private void countOfVeryGoodToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show(VeryGood.Count().ToString());
        }

        private void peekOfPeekToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show(Good.Peek().name);
        }

        private void removeItemFromFailedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show(fail.Dequeue().name);
        }

        private void countOfPassedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show(pass.Count().ToString());
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();

        }
        }
    }

and in form2 contain textboxes to add new item for these list ! how use this !

posted Apr 5, 2015 by As M Ob

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
+2 votes

if form1 include textbox - then selected word from it and
go to form2 to input new word and replace it with selected word
then display form1 with textbox that include the new word

+1 vote

Develop a C# windows form application that allows users to do all of the following:
Import a text from a text file (*.txt).The input file is selected from an open file dialog.
Successfully imported text is displayed on a text box.
Analyze a selected character.

For example the selected char is # :
is Digit :False
is letter :False
is letter or Digit :False
is lower :False
is upper :False
is punctuation :True
is symbol :False

then :
Calculate number of lines in the imported text.
Calculate number of words in the imported text.
Calculate number of letters in the imported text.
Calculate number of digits in the imported text.
Calculate number of uppers in the imported text.
Replace a selected word by anything else.

+2 votes

Develop a C# Windows Form Application that allows users to do all of the following.
Read a List of patient's information from a text file (*.txt), the input text file is selected from the Open File Dialog.
Your program should accept any text file with the following format:
a. The file contains columns with Basic information about patients.
b. Columns may be separated by spaces and/or tabs.
c. The first line in the file is the column header.
d. After the header, each line represents a Patient (name, address, phone#, Bdate, gander ,wheight, height and blood type).
e. Successfully imported patients are displayed on a data grid view in a second form and added to a patient list.

  1. The user will be able to display on The Grid view :
    a) Female patients.
    b) Patients with age<45 year. c) Save Over weighted patients on a text file .  Note: To find over weighted patients you have to calculate the BMI value. BMI=Weight/ (Height*Height). If BMI <18.5 >>>>> under weighted.
    18.5<=BMI<=25 >>>>>>>Normal.
    BMI>25 >>>>>>>>>>>> Over Weighted.
...