Questions on DataGridView and XML File as Data Source

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stewart Berman

    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(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?


  • Zhi-Xin Ye [MSFT]

    #2
    RE: Questions on DataGridView and XML File as Data Source

    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.ReadXml Schema() method instead. For example:

    gridDataSet.Rea dXmlSchema("E:\ \ImageControl.x ml");

    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:
    msdnmg@microsof t.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

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

    Comment

    • Stewart Berman

      #3
      Re: Questions on DataGridView and XML File as Data Source

      >To show only the headers in the DataGridView, you can call the
      >DataSet.ReadXm lSchema() method instead. For example:
      >
      >gridDataSet.Re adXmlSchema("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.D ataSource = gridDataSet;
      gridDataSet.Rea dXmlSchema("E:\ \DataSet1.xsd") ; // Loads the schema
      gridDataSet.Rea dXml("E:\\Image Control.xml"); // Loads 0 or more records
      dataGridView1.D ataMember = "Images"; // Identifies the table
      // Grid formatting
      dataGridView1.A utoSizeColumnsM ode = DataGridViewAut oSizeColumnsMod e.Fill;
      dataGridView1.C olumnHeadersVis ible = true;
      // Hide the column containing the sequence number
      dataGridView1.C olumns.GetFirst Column(DataGrid ViewElementStat es.Visible).Vis ible = 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-zhye@online.mic rosoft.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.ReadXm lSchema() method instead. For example:
      >
      >gridDataSet.Re adXmlSchema("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:
      >msdnmg@microso ft.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.

      Comment

      • Zhi-Xin Ye [MSFT]

        #4
        Re: Questions on DataGridView and XML File as Data Source

        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:
        msdnmg@microsof t.com.

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

        Comment

        Working...