Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6700435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:48:50+00:00 2026-05-26T06:48:50+00:00

I have a datagridview populated with data from an .xml file. The data is

  • 0

I have a datagridview populated with data from an .xml file. The data is a list of MyObjects, where MyObject is a C# class I have. This initially was done without a schema, so no type information 🙁 Means I don’t get the benefit of auto-generated checkbox columns for bools, etc. in the MyObject class.

So I used xsd.exe to generate an .xsd file. Looks great! But how do I deploy this .xsd with the app? Do I have to make sure it sits in the same directory as my app and load it like:

DataSet ds = new DataSet();
ds.ReadXml("mystuff.xml");
ds.ReadXmlSchema("myschema.xsd");
dataGridView_1.DataSource = ds;
dataGridView_1.DataMember = "MyObject";

I’m sure there’s a better way to handle this… can I include it as part of the assembly or something? Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:48:51+00:00Added an answer on May 26, 2026 at 6:48 am

    Make it an embedded strongly-typed resource.

    Add the file to your project and give it a Build Action of “Content”, and “Do Not Copy”. Then open up the Resources designer tab (either from the Properties folder, or in the Project Properties dialog) and drag the file onto the Resource Designer canvas. The file is now embedded into your assembly. This will produce a strongly-typed property of the default Resources class, with the same name as the file it came from.

    To load it into the data set you can hook up a StringReader to it. Note that you almost always want to load the schema first, as it changes the behavior of ReadXml:

    var ds = new DataSet();
    using (var rdr = new StringReader(Properties.Resources.myschema))
    {
        ds.ReadXmlSchema(rdr);
    }
    ds.ReadXml("mystuff.xml", XmlReadMode.IgnoreSchema);
    

    For XmlReadMode you have a couple of options. They dictate what happens if your data doesn’t match your schema, and what to do if there’s a schema defined inline in the XML file that differs from the one you already loaded:

    • XmlReadMode.ReadSchema will import any inline schema as long as it doesn’t collide with the already-loaded schema; if there are name collisions, the ReadXml will throw; or
    • XmlReadMode.IgnoreSchema will ignore any inline schema, and try to force the data to the schema you specified. In this mode, data that doesn’t match your schema will not end up in the dataset.
    • XmlReadMode.InferSchema will ignore any inline schema, but in this case, any data that doesn’t conform to your schema will cause your schema to be extended; for example, if your XML file has a table that isn’t in your schema, that table will get added to your schema and the data imported. If there are name collisions between columns of different types, ReadXml will throw;

    If you do the ReadXml first, you always get ReadSchema mode if there’s an inline schema, or InferSchema mode if there isn’t. Even if that’s what you want it’s better to be explicit about it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGridView populated with a BindingList . This list gets saved into
I have data from a CD or Record currently setup like this: class Release
I have a datagridview and a combobox which get populated randomly with data. However,
This is what I am trying to achieve: DataTable populated using data from non
I have a datagrid that is populated via XML file when the form loads.
A few days back I had to de-serialize data from xml file to my
I have a DataGridView being regularly populated via data-bound objects, and the number of
I'm taking data from a list that I populate a DataGridView with and am
I have a DataGridView that I'm populating from a list. The function that edits
I have a DataGridView bound to a DataTable. The DataTable is populated from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.