XmlTextWriter and XML in Datagrid

A

Arda Coskun

Hi,

I have a problem about XmlTextWriter class.

XmlTextWriter writer = new
XmlTextWriter(Assembly.GetCallingAssembly().GetManifestResourceStream("Conso
leApplication1.XMLs.GameScores.xml"), System.Text.Encoding.ASCII);

Gives error on this line;

An unhandled exception of type 'System.ArgumentNullException' occurred in
mscorlib.dll

Additional information: Value cannot be null.

I set my XML, GameScores.xml, as embedded source.

Second question is;

I want to display my XML file into a datagrid in Smartphone 2003 OS. I'm
using .NET Compact Framework C#.

I drag and drop DataGrid control from toolbox, but compiler gives error
about missing an assemly.

private System.Windows.Forms.DataGrid dataGrid1;
There is no DataGrid class in System.Windows.Forms namespace it says? Can
anyone give me an example how to solve this?

Any help would be appriciated.

Arda
 
J

Jon Skeet [C# MVP]

Arda Coskun said:
I have a problem about XmlTextWriter class.

XmlTextWriter writer = new
XmlTextWriter(Assembly.GetCallingAssembly().GetManifestResourceStream("Conso
leApplication1.XMLs.GameScores.xml"), System.Text.Encoding.ASCII);

Gives error on this line;

An unhandled exception of type 'System.ArgumentNullException' occurred in
mscorlib.dll

Additional information: Value cannot be null.

I set my XML, GameScores.xml, as embedded source.

I suspect you'll find that GetManifestResourceStream is returning null.
If you break your line up into several lines, one for each operation,
you'll find it a lot easier to work out where the actual problem is.
Second question is;

I want to display my XML file into a datagrid in Smartphone 2003 OS. I'm
using .NET Compact Framework C#.

I drag and drop DataGrid control from toolbox, but compiler gives error
about missing an assemly.

private System.Windows.Forms.DataGrid dataGrid1;
There is no DataGrid class in System.Windows.Forms namespace it says? Can
anyone give me an example how to solve this?

Don't know about that one, I'm afraid.
 
I

Ilya Tumanov [MS]

You can not display XML in a DataGrid without loading it first into memory
(I'm assuming you want to display data loaded from XML, not the XML itself).
Easiest way to accomplish that would be to load XML into the DataSet using
DataSet.ReadXml() and bind a table you want to see to a control.

Alternatively, you can use XmlTextReader class (not XmlTextWriter which is
used save data into XML files) to load XML data into your custom class.
As soon as it's done, you can bind it to a control.

Also, I don't believe DataGrid is supported on a Smart Phone, you would
have to use some other control do display data (e.g., list view).

As to exception you're getting, that's most likely because
GetManifestResourceStream() was unable to find requested resource.
Make sure you have it. Again, it won't work even if you fix this resource
problem.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
A

Arda Coskun

Hi Jon,

I solved the XML writer problem. I made the XML file as a normal source not
embedded one and it worked. However, I have another problem, when user shut
downs the phone and reopen it, inside of my XML is going away I want it not
to lose last changes.

How can I solve it? Thanks.
 
J

Jon Skeet [C# MVP]

Arda Coskun said:
I solved the XML writer problem. I made the XML file as a normal source not
embedded one and it worked. However, I have another problem, when user shut
downs the phone and reopen it, inside of my XML is going away I want it not
to lose last changes.

How can I solve it? Thanks.

Well, presumably you just need to rewrite the XML when the user makes a
change...
 
Top