Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
|
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 1st, 2009, 09:58 AM
Authorized User
 
Join Date: Nov 2006
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default Creating XML data from DataGridView

I didn't see a post anywhere on this and have been looking around trying to see if there is something already built in the .Net Framework but don't see it.

I want to use DataGridView (DGV) to allow users to create some data that I will store as XML for the application to use later. The DGV is a nice tool for displaying data and allowing users to edit it. I've done this sort of thing in the past by reading the rows and columns out of the DGV and creating the XML objects using XMLDocument. But it seems to me that this is a common enough task that Microsoft would have built it into a DataBinding or some thing to allow you to use DataSets and DataTables to reduce the coding required to do in manually.

Everything I've found so far seems to want you to manually build the XML document mimicking the columns you have already defined using the DGV gui when you desigend the form. Before I run off and build this myself, is anyone aware of class in the framework that does this? And how to use it to generate the DataTable from the DGV?
__________________
What you don\'t know can hurt you!
 
Old October 1st, 2009, 10:07 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

DataSet.GetXml will return an XML representation of the data in a dataset. This might not be in the XML format you want however.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old October 1st, 2009, 10:54 AM
Authorized User
 
Join Date: Nov 2006
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default RE: Creating XML data from DataGridView

Sam, if I understand it correctly DataSet.GetXML requires the DataSet to already be defined. I want to define the DataTables in the DataSet automatically at run time from the structure of the DataGridView as defined at design time.

I can do this by extending DataGridView to provide a method that creates a DataTable as mentioned and then binds it to the DataGridView. I notice that if you try to assign a BindingSource to a DGV that has not been previously bound you get a Null value.

I am looking for Microsoft to have provided this functionality somewhere as it seems to me to be a common requirement.
__________________
What you don\'t know can hurt you!





Similar Threads
Thread Thread Starter Forum Replies Last Post
append data in datagridview harisbscs2003 C# 2005 3 March 4th, 2009 06:52 AM
capture data in datagridview stealthdevil Visual Basic 2005 Basics 0 January 23rd, 2008 06:49 PM
How do i Update data through a datagridview jazzydonald VB How-To 0 October 26th, 2007 02:52 AM
Save data on datagridview salemkoten SQL Server 2005 1 November 2nd, 2006 11:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.