Question

In: Computer Science

Hello! I need to present my xml file on the Windows form application I tried but...

Hello!

I need to present my xml file on the Windows form application I tried but it dosent work at button 2, I cann't show Xml_file. What is problem here please? have you any suggest or solution .

Here is my form code!

namespace MyFirstWindos
{
 public partial class Form1 : Form
 {
    const string XML1 = "path";
    const string XML2 = "Path";
    const string ResultFile = "Path"; 

    public Form1()
    {
        InitializeComponent();
    }

    private void Run(object sender, EventArgs e)//run button
    {
        Compare_D_R d_R = new Compare_D_R();
        d_R.compareD_R();
    }

    private void Button3_Click(object sender, EventArgs e)
    {
        xmlGridView.ClearSelection();

    }

    private void Button2_Click(object sender, EventArgs e)//show
    {
        if (showinput.Text != null) {
            string DefaultFile = "DefaultFile": 
            string Alternative = "AlternativeFile";
            string Result = "ResultFile";

            if (  DefaultFile==showinput.Text) {
                DataSet ds = new DataSet();
               xmlGridView.DataSource = ds.ReadXml(XML1);

            }
            if (Alternative == showinput.Text) {
                xmlGridView.DataSource = XML2;
            }
            if (Result == showinput.Text)
            {
                xmlGridView.DataSource = ResultFile;
            }
            else
            {
                MessageBox.Show("Invalid Input");
                showinput.Text = string.Empty;
                showinput.Focus();
            }

        }

    }

    private void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }

    private void XmlGridView_CellContentClick(object     sender,DataGridViewCellEventArgs e)
    {

    }

    private void Button4_Click(object sender, EventArgs e)
    {

    }
 }
 }

How can I play/show my xml_file on the grid view. I'm really new in winform so please try to understand my question. if you have a better Idea you are welcome it is a free desigen.

Thanks:

Solutions

Expert Solution

Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks.

  if (  DefaultFile==showinput.Text) {
                DataSet ds = new DataSet();
               xmlGridView.DataSource = ds.ReadXml(XML1); THIS IS WRONG

            }
            if (Alternative == showinput.Text) {
                xmlGridView.DataSource = XML2; THIS IS ALSO WRONG
            }

Actual should be like :

DataSet dataSet = new DataSet();
dataSet.ReadXml(@"sample.xml");
xmlGridView.DataSource = dataSet.Tables[0];

YOU ARE MISSING THE PART WHERE FROM DATASET YOU HAVE TO READ TABLE
  

Sampel run:


Related Solutions

Hello I need a small fix in my program. I need to display the youngest student...
Hello I need a small fix in my program. I need to display the youngest student and the average age of all of the students. It is not working Thanks. #include <iostream> #include <iomanip> #include <fstream> #include <vector> #include <algorithm> using namespace std; struct Student { string firstName; char middleName; string lastName; char collegeCode; int locCode; int seqCode; int age; }; struct sort_by_age { inline bool operator() (const Student& s1, const Student& s2) { return (s1.age < s2.age); // sort...
i need to post a file to a url. The "Content-Type: multipart/form-data" and it "accept: application/json"...
i need to post a file to a url. The "Content-Type: multipart/form-data" and it "accept: application/json" i need to upload a file, three strings. It needs to be in Java, but i keep getting issues.
Hello, I need an expert answer for one of my JAVA homework assignments. I will be...
Hello, I need an expert answer for one of my JAVA homework assignments. I will be providing the instructions for this homework below: For this lab, you will write the following files: AbstractDataCalc AverageDataCalc MaximumDataCalc MinimumDataCalc As you can expect, AbstractDataCalc is an abstract class, that AverageDataCalc, MaximumDataCalc and MinimumDataCalc all inherit. We will provide the following files to you: CSVReader A simple CSV reader for Excel files DataSet This file uses CSVReader to read the data into a List>...
Hello, I need to do a research and I choose my research question: Do the commercialization...
Hello, I need to do a research and I choose my research question: Do the commercialization and use of civilian drones respect our individual freedoms and privacy? Can you help me with ideas of Research Methodology including: 1. Restatement of research tasks: hypothesis or research questions; 2. Study population and sampling: description of study areas (where? why?), populations and the procedures for the sample selection; 3. Data collection: description of the tools (i.e. the survey instrument) and methods used (i.e....
c# Create a console application that protects an XML file, such as the following example. Note...
c# Create a console application that protects an XML file, such as the following example. Note that the customer's credit card number and password are currently stored in clear text. The credit card must be encrypted so that it can be decrypted and used later, and the password must be salted and hashed: <?xml version="1.0" encoding="utf-8" ?> <customers> <customer> <name>Bob Smith</name> <creditcard>1234-5678-9012-3456</creditcard> <password>Pa$$w0rd</password> </customer> </customers>
Hello, I need to divide my code in this different parts. Use a standard approach to...
Hello, I need to divide my code in this different parts. Use a standard approach to source files in this assignment: a .cpp for each function (you have at least two – main and ageCalc) a header file for the student struct, properly guarded Code: #include <iostream> #include <string> #include <fstream> #include <algorithm> #include <vector> #include <iomanip> using namespace std; #define nullptr NULL #define MAX_SIZE 100 struct Student {     string firstName;     char middleName;     string lastName;     char collegeCode;     int locCode;     int...
Hello, I need to divide my code in this different parts. Use a standard approach to...
Hello, I need to divide my code in this different parts. Use a standard approach to source files in this assignment: a .cpp for each function (you have at least two – main and ageCalc) a header file for the student struct, properly guarded Code: #include <iostream> #include <string> #include <fstream> #include <algorithm> #include <vector> #include <iomanip> using namespace std; #define nullptr NULL #define MAX_SIZE 100 struct Student {     string firstName;     char middleName;     string lastName;     char collegeCode;     int locCode;     int...
Hello, I need to divide my code in this different parts. Use a standard approach to...
Hello, I need to divide my code in this different parts. Use a standard approach to source files in this assignment: a .cpp for each function (you have at least two – main and ageCalc) a header file for the student struct, properly guarded Code: #include <iostream> #include <string> #include <fstream> #include <algorithm> #include <vector> #include <iomanip> using namespace std; #define nullptr NULL #define MAX_SIZE 100 struct Student {     string firstName;     char middleName;     string lastName;     char collegeCode;     int locCode;     int...
Hello, I need to divide my code in this different parts. Use a standard approach to...
Hello, I need to divide my code in this different parts. Use a standard approach to source files in this assignment: a .cpp for each function (you have at least two – main and ageCalc) a header file for the student struct, properly guarded Code: #include <iostream> #include <string> #include <fstream> #include <algorithm> #include <vector> #include <iomanip> using namespace std; #define nullptr NULL #define MAX_SIZE 100 struct Student {     string firstName;     char middleName;     string lastName;     char collegeCode;     int locCode;     int...
I need to write a java program (in eclipse) that will read my text file and...
I need to write a java program (in eclipse) that will read my text file and replace specific placeholders with information provided in a second text file. For this assignment I am given a text file and I must replace <N>, <A>, <G>, with the information in the second file. For example the information can be John 22 male, and the template will then be modified and saved into a new file or files (because there will be multiple entries...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT