473,387 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Questions on DataGridView and XML File as Data Source

I have an application that populates a DataGridView control with an XML file:
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = gridDataSet;
gridDataSet.ReadXml("E:\\ImageControl.xml");
dataGridView1.DataMember = "Images";
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView1.ColumnHeadersVisible = true;
dataGridView1.Columns.GetFirstColumn(DataGridViewE lementStates.Visible).Visible = false;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false;
}

The interface has an Add and a Delete button for adding and deleting entries.

How do I setup the XML file so the grid only shows the headers?
The schema is:
<?xml version="1.0" standalone="yes" ?>
<xs:schema id="DataSet1" targetNamespace="http://www.tempuri.org/DataSet1.xsd"
xmlns:mstns="http://www.tempuri.org/DataSet1.xsd"
xmlns="http://www.tempuri.org/DataSet1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified"
elementFormDefault="qualified">
<xs:element name="DataSet1" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Images" minOccurs="0" >
<xs:complexType>
<xs:sequence>
<xs:element name="Sequence"
msdata:AutoIncrement="true" type="xs:int" />
<xs:element name="Name" type="xs:string"
minOccurs="0" />
<xs:element name="Location" type="xs:string"
minOccurs="0" />
<xs:element name="Style" type="xs:string"
minOccurs="0" />
<xs:element name="Duration" type="xs:int"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

The initial XML file has:
<?xml version="1.0" encoding="utf-8"?>
<DataSet1 xmlns="http://www.tempuri.org/DataSet1.xsd">
<!--SABBackgroundSlideShow Image Conrol-->
<Images>
<Sequence></Sequence>
<Name></Name>
<Location></Location>
<Style></Style>
<Duration></Duration>
</Images>
</DataSet1>

When the application opens the grid shows the headers and a row of empty cells. If I delete the
<Imagessection. The system complains that it cannot find the table. If I delete just the children
un Images the system complains that there aren't any child entries defined.

So how do I stop the empty row from displaying?
Nov 15 '08 #1
3 5616
Hello Stewart,

Thank you for using Microsoft Managed Newsgroup Service. My name is Zhi-Xin
Ye, it's my pleasure to work with you on this issue.

To show only the headers in the DataGridView, you can call the
DataSet.ReadXmlSchema() method instead. For example:

gridDataSet.ReadXmlSchema("E:\\ImageControl.xml");

Please try my suggestion and let me know the result.

Have a splendid day!

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 17 '08 #2
>To show only the headers in the DataGridView, you can call the
>DataSet.ReadXmlSchema() method instead. For example:

gridDataSet.ReadXmlSchema("E:\\ImageControl.xml") ;
Actual the solution was as follows:
Starting with an empty XML filet:
<?xml version="1.0" standalone="yes"?>
<DataSet1 xmlns="http://www.tempuri.org/DataSet1.xsd">
</DataSet1>

In the form load event:
// Configure the DataGridView control
dataGridView1.DataSource = gridDataSet;
gridDataSet.ReadXmlSchema("E:\\DataSet1.xsd"); // Loads the schema
gridDataSet.ReadXml("E:\\ImageControl.xml"); // Loads 0 or more records
dataGridView1.DataMember = "Images"; // Identifies the table
// Grid formatting
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView1.ColumnHeadersVisible = true;
// Hide the column containing the sequence number
dataGridView1.Columns.GetFirstColumn(DataGridViewE lementStates.Visible).Visible = false;

It is necessary to read the schema from the DataSet1.xsd file not the Images.xml file. This should
always be done anyway as it assigns the field attributes. For example the Sequence field is
supposed to have the AutoIncrement attribute. If you don't read the schema from the DataSet1.xsd
file it doesn't have that attribute.
v-****@online.microsoft.com (Zhi-Xin Ye [MSFT]) wrote:
>Hello Stewart,

Thank you for using Microsoft Managed Newsgroup Service. My name is Zhi-Xin
Ye, it's my pleasure to work with you on this issue.

To show only the headers in the DataGridView, you can call the
DataSet.ReadXmlSchema() method instead. For example:

gridDataSet.ReadXmlSchema("E:\\ImageControl.xml") ;

Please try my suggestion and let me know the result.

Have a splendid day!

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

================================================= =
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
================================================= =
This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 18 '08 #3
Hi Stewart,

Yes, it necessary to call the ReadXmlSchema() method to read the schema.
And do you need further help on this issue? Please let me know if there is
anything I can do to help you.

Best Regards,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

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

Nov 19 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mark carew | last post by:
Hi, Problem - An extra column to the left (even with row headers disabled) ---------------------------------------------------------- Apologies if this posting is already in the newsgroup; but...
10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
4
by: shibeta | last post by:
Hello, I have problem with DataGridView and BindingSource. I have created DataSet and added TableData to it with manualy created columns (without DataAdapter - I'm not using MSSQL). On the Form I...
4
by: Peter Forman | last post by:
I have a windows form that contains a datagridview containing manipulated data from various sources (numerous sql servers + xml files). I now need to create a report from the data in the...
1
by: TG | last post by:
Hi! I have an application in which I have some checkboxes and depending which ones are checked those columns will show in the datagridview from sql server or no. After that I have 2 buttons:...
2
by: TG | last post by:
Hi! I am trying to export only the visible columns from a datagridview in my windows form in VB 2008. Should't it be no comma after the first row where the headers are? Also should...
1
by: Andrus | last post by:
I have Winforms DataGridView whose DataSource Rids is Marc sample TableListCollection<TRowderived from BindingList. It is used to edit invoice rows. If user presses Revert button, my application...
2
by: Stewart Berman | last post by:
I have an application that populates a DataGridView control with an XML. file. 1. How do I set up the process so the user initally sees just the headers -- no records. I have the DataGridView...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.