I have an application that populates a DataGridView control with an XML file:
private void Form1_Load(obje ct sender, EventArgs e)
{
dataGridView1.D ataSource = gridDataSet;
gridDataSet.Rea dXml("E:\\Image Control.xml");
dataGridView1.D ataMember = "Images";
dataGridView1.A utoSizeColumnsM ode = DataGridViewAut oSizeColumnsMod e.Fill;
dataGridView1.C olumnHeadersVis ible = true;
dataGridView1.C olumns.GetFirst Column(DataGrid ViewElementStat es.Visible).Vis ible = false;
dataGridView1.A llowUserToAddRo ws = false;
dataGridView1.A llowUserToDelet eRows = 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="ht tp://www.tempuri.org/DataSet1.xsd"
xmlns="http://www.tempuri.org/DataSet1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata" attributeFormDe fault="qualifie d"
elementFormDefa ult="qualified" >
<xs:element name="DataSet1" msdata:IsDataSe t="true">
<xs:complexType >
<xs:choice maxOccurs="unbo unded">
<xs:element name="Images" minOccurs="0" >
<xs:complexType >
<xs:sequence>
<xs:element name="Sequence"
msdata:AutoIncr ement="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">
<!--SABBackgroundSl ideShow 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
<Imagessectio n. 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?
private void Form1_Load(obje ct sender, EventArgs e)
{
dataGridView1.D ataSource = gridDataSet;
gridDataSet.Rea dXml("E:\\Image Control.xml");
dataGridView1.D ataMember = "Images";
dataGridView1.A utoSizeColumnsM ode = DataGridViewAut oSizeColumnsMod e.Fill;
dataGridView1.C olumnHeadersVis ible = true;
dataGridView1.C olumns.GetFirst Column(DataGrid ViewElementStat es.Visible).Vis ible = false;
dataGridView1.A llowUserToAddRo ws = false;
dataGridView1.A llowUserToDelet eRows = 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="ht tp://www.tempuri.org/DataSet1.xsd"
xmlns="http://www.tempuri.org/DataSet1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata" attributeFormDe fault="qualifie d"
elementFormDefa ult="qualified" >
<xs:element name="DataSet1" msdata:IsDataSe t="true">
<xs:complexType >
<xs:choice maxOccurs="unbo unded">
<xs:element name="Images" minOccurs="0" >
<xs:complexType >
<xs:sequence>
<xs:element name="Sequence"
msdata:AutoIncr ement="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">
<!--SABBackgroundSl ideShow 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
<Imagessectio n. 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?
Comment