Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 1st, 2009, 09:58 AM
Authorized User
 
Join Date: Nov 2006
Location: Valparaiso, IN, USA.
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!
  #2 (permalink)  
Old October 1st, 2009, 10:07 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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?
  #3 (permalink)  
Old October 1st, 2009, 10:54 AM
Authorized User
 
Join Date: Nov 2006
Location: Valparaiso, IN, USA.
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!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:05 AM.


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