Use dataset and datagridview to read XML files to datagridview.

Source: Internet
Author: User
Haha! You are familiar with dataset, datagridview, and XML! I will not introduce it here. Let's go straight to the theme! The key section is provided here. Code ! For reference only

Code
// I am writing it in the loading event of the form.
Private   Void Form1_load ( Object Sender, eventargs E)
{
// Instantiate a DataSet object to read data in the XML file.
Dataset Set   =   New Dataset ();
// Use set to read XML files
Set . Readxml ( @" E: \ xmlfile. xml " );
// Set the data source of the datagridview
Datagridview. datasource =   Set . Tables [ 0 ];
}

Since the XML file can be read to the datagridview, can the data of the XML file be modified in the datagridview? The answer is yes! In fact, the Code is also very simple!

Code
1 // Button clicking event
2 Private   Void Button_click ( Object Sender, eventargs E)
3 {< br> 4 // it is also called (Dataset) set writexml ()
5 set . writexml ( @ " E: \ xmlfile. XML " );
6 // the set object here is the set object instantiated above. The same object is used in the same form.
7 }
8

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.