Version

EnforceXsdConstraints(String) Method

Applies the constraints found in the XSD schema contained in the specified file to the bands and columns of the grid.
Syntax
'Declaration
 
Public Overloads Sub EnforceXsdConstraints( _
   ByVal filePath As String _
) 
public void EnforceXsdConstraints( 
   string filePath
)

Parameters

filePath
The path to a file containing an XSD schema.
Remarks

There are a couple requirements imposed on the XSD schema passed to this method.

  1. "The XSD namespace ("http://www.w3.org/2001/XMLSchema") must have a prefix associated with it (such as 'xs' or 'xsd').
  2. "The schema's target namespace must be the default namespace (i.e. cannot have a prefix associated with it).

This overload uses All to specify which constraints should be applied.

Example
This snippet demonstrates how to use the EnforceXsdConstraints method on the UltraGrid.

' simpleSchema.xsd
' ******************************************************************************
<xs:schema  targetNamespace="http://tempuri.org/simpleSchema.xsd"
			elementFormDefault="qualified"
			xmlns="http://tempuri.org/simpleSchema.xsd"			
			xmlns:xs="http://www.w3.org/2001/XMLSchema" 
			xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">			
    <xs:element name="MyDataSet" msdata:IsDataSet="true">
		<xs:complexType>
			<xs:choice maxOccurs="unbounded">
				<!-- Declares a table of data called "People" which must have between 1 and 5 rows of data. -->			
				<xs:element name="People" minOccurs="1" maxOccurs="5">
					<xs:complexType>
						<xs:sequence>						
							<!-- Declares a column called "Name" of type string where the 
							     length of the value must be at most 30 characters.  Setting 
							     'minOccurs' to 1 indicates that cells in this column cannot be empty/null. -->
							<xs:element name="Name" minOccurs="1">
								<xs:simpleType>
									<xs:restriction base="xs:string">
										<xs:maxLength value="30" />
									</xs:restriction>
								</xs:simpleType>
							</xs:element>
							
							<!-- Declares a DateTime column called "DateOfBirth". -->
							<xs:element name="DateOfBirth"  type="xs:dateTime" />							
						</xs:sequence>
						
						<!-- Declares a column called "IsFamous" which is represented in XML as an attribute. -->
						<xs:attribute name="IsFamous" type="xs:boolean" />						
					</xs:complexType> 
				</xs:element>
			</xs:choice>					
		</xs:complexType>				
    </xs:element>                         
</xs:schema>

' MyApp.cs
' ******************************************************************************
Private Sub SetupGrid()
   ' Create a DataSet and then read its structure in from the XSD schema file.
   '
   Dim ds As New DataSet()
   ds.ReadXmlSchema("..\simpleSchema.xsd")
   
   ' Get a reference to the "People" table.
   '
   Dim tbl As DataTable = ds.Tables("People")
   
   ' Add a few rows of data: People(IsFamous, Name, DateOfBirth)
   '
   tbl.Rows.Add(New Object() {True, "Ludwig Van Beethoven", New DateTime(1770, 12, 17)})
   tbl.Rows.Add(New Object() {False, "Joe Nobody", New DateTime(1972, 11, 2)})
   tbl.Rows.Add(New Object() {True, "Pablo Picasso", New DateTime(1881, 10, 25)})
   
   ' Bind the grid to the DataSet object.
   '
   Me.ultraGrid1.DataSource = ds

   ' Allow for new rows to be added.
   '
   Me.ultraGrid1.DisplayLayout.Override.AllowAddNew = AllowAddNew.TemplateOnBottom
   
   ' Inform the grid that it should enforce the constraints found in the XSD schema
   ' which are not honored by the DataSet.
   '
   Me.ultraGrid1.EnforceXsdConstraints("..\simpleSchema.xsd")
End Sub
// simpleSchema.xsd
// ******************************************************************************
<xs:schema  targetNamespace="http://tempuri.org/simpleSchema.xsd"
			elementFormDefault="qualified"
			xmlns="http://tempuri.org/simpleSchema.xsd"			
			xmlns:xs="http://www.w3.org/2001/XMLSchema" 
			xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">			
    <xs:element name="MyDataSet" msdata:IsDataSet="true">
		<xs:complexType>
			<xs:choice maxOccurs="unbounded">
				<!-- Declares a table of data called "People" which must have between 1 and 5 rows of data. -->			
				<xs:element name="People" minOccurs="1" maxOccurs="5">
					<xs:complexType>
						<xs:sequence>						
							<!-- Declares a column called "Name" of type string where the 
							     length of the value must be at most 30 characters.  Setting 
							     'minOccurs' to 1 indicates that cells in this column cannot be empty/null. -->
							<xs:element name="Name" minOccurs="1">
								<xs:simpleType>
									<xs:restriction base="xs:string">
										<xs:maxLength value="30" />
									</xs:restriction>
								</xs:simpleType>
							</xs:element>
							
							<!-- Declares a DateTime column called "DateOfBirth". -->
							<xs:element name="DateOfBirth"  type="xs:dateTime" />							
						</xs:sequence>
						
						<!-- Declares a column called "IsFamous" which is represented in XML as an attribute. -->
						<xs:attribute name="IsFamous" type="xs:boolean" />						
					</xs:complexType> 
				</xs:element>
			</xs:choice>					
		</xs:complexType>				
    </xs:element>                         
</xs:schema>

// MyApp.cs
// ******************************************************************************
private void SetupGrid()
{
	// Create a DataSet and then read its structure in from the XSD schema file.
	//
	DataSet ds = new DataSet();
	ds.ReadXmlSchema( "..\\..\\simpleSchema.xsd" );

	// Get a reference to the "People" table.
	//
	DataTable tbl = ds.Tables["People"];

	// Add a few rows of data: People(IsFamous, Name, DateOfBirth)
	//
	tbl.Rows.Add( new object[]{ true,  "Ludwig Van Beethoven", new DateTime( 1770, 12, 17 ) } );
	tbl.Rows.Add( new object[]{ false, "Joe Nobody", new DateTime( 1972, 11,  2 ) } );
	tbl.Rows.Add( new object[]{ true,  "Pablo Picasso", new DateTime( 1881, 10, 25 ) } );

	// Bind the grid to the DataSet object.
	//
	this.ultraGrid1.DataSource = ds;

	// Allow for new rows to be added.
	//
	this.ultraGrid1.DisplayLayout.Override.AllowAddNew = AllowAddNew.TemplateOnBottom;

	// Inform the grid that it should enforce the constraints found in the XSD schema
	// which are not honored by the DataSet.
	//
	this.ultraGrid1.EnforceXsdConstraints( "..\\..\\simpleSchema.xsd" );
}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also