In: Computer Science
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:
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:
