473,563 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

save DataGridView to Xml

Hello Gurus,
I want to save the state of an unbound DataGridView on my Windows Form
application to an XML file so i can later load it back..

Basically, on my form I have a DataGridView, it's got some
DataGridViewTex tBoxCell, DataGridViewCom boBoxCell etc, i want to export all
that to XML..

Any help is greatly appreciated.

Mar 13 '06 #1
10 39454
Do you really want to save a TextBox, ComboBox and data to an XML file?

Generally DataGrids are displaying data from a DataSet, you can save
the data within a DataSet through the DataSet.WriteXm l() method.

The DataSet Class:
http://msdn.microsoft.com/library/de...ClassTopic.asp

Mar 13 '06 #2
What i wanted to store was the value of those items, while i can iterate
create line by line the xml file, i would much rather use the dataset and
WriteXml method, but for some reason i was not able to do so for an unbound
DataGridView. the user creates the rows and sets the values, then when they
click save, i want to output all the data to an XML file, idealy, i want to
extract the DataSet of the DataGridView to save it to XML using the WriteXML
method mentioned, but i was not able to get it.

Do i make sense?

"A.Kahtava" <ka*****@gmail. com> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.com.. .
Do you really want to save a TextBox, ComboBox and data to an XML file?

Generally DataGrids are displaying data from a DataSet, you can save
the data within a DataSet through the DataSet.WriteXm l() method.

The DataSet Class:
http://msdn.microsoft.com/library/de...ClassTopic.asp

Mar 13 '06 #3
anyone?

"Henok Girma" <no****@spamfre e.com> wrote in message
news:Qd5Rf.8179 25$x96.97819@at tbi_s72...
What i wanted to store was the value of those items, while i can iterate
create line by line the xml file, i would much rather use the dataset and
WriteXml method, but for some reason i was not able to do so for an
unbound DataGridView. the user creates the rows and sets the values, then
when they click save, i want to output all the data to an XML file,
idealy, i want to extract the DataSet of the DataGridView to save it to
XML using the WriteXML method mentioned, but i was not able to get it.

Do i make sense?

"A.Kahtava" <ka*****@gmail. com> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.com.. .
Do you really want to save a TextBox, ComboBox and data to an XML file?

Generally DataGrids are displaying data from a DataSet, you can save
the data within a DataSet through the DataSet.WriteXm l() method.

The DataSet Class:
http://msdn.microsoft.com/library/de...ClassTopic.asp


Mar 13 '06 #4
Henok Girma wrote:
anyone?


It would help if you gave a bit more information. "I was not able to
get it" doesn't give us much to go on.

Could you post a short but complete program that demonstrates the
problem? See
http://www.pobox.com/~skeet/csharp/complete.html for what I mean by
that.

Jon

Mar 13 '06 #5
A DataGridView is a user interface component, not a data component. It is
bound to a DataSet by means of a BindingSource, which relates the data in a
particular table or view in the DataSet to the DataGridView. The
DataGridView then uses the BindingSource to display the data in a meaningful
way. Therefore, you don't want to serialize a DataGridView at all; you want
to serialize the data that is contained (or rather "displayed" ) in it. This
would entail serializing the DataSet.

As to why you were "not able to get it," that is the crux of the problem,
and cannot be answered until you describe exactly what you tried, and what
the results were.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

"Henok Girma" <no****@spamfre e.com> wrote in message
news:SWeRf.8196 02$x96.730159@a ttbi_s72...
anyone?

"Henok Girma" <no****@spamfre e.com> wrote in message
news:Qd5Rf.8179 25$x96.97819@at tbi_s72...
What i wanted to store was the value of those items, while i can iterate
create line by line the xml file, i would much rather use the dataset and
WriteXml method, but for some reason i was not able to do so for an
unbound DataGridView. the user creates the rows and sets the values, then
when they click save, i want to output all the data to an XML file,
idealy, i want to extract the DataSet of the DataGridView to save it to
XML using the WriteXML method mentioned, but i was not able to get it.

Do i make sense?

"A.Kahtava" <ka*****@gmail. com> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.com.. .
Do you really want to save a TextBox, ComboBox and data to an XML file?

Generally DataGrids are displaying data from a DataSet, you can save
the data within a DataSet through the DataSet.WriteXm l() method.

The DataSet Class:
http://msdn.microsoft.com/library/de...ClassTopic.asp



Mar 13 '06 #6
ok, now we are getting somewhere.. i understand about the DataSet and the
bindingsource etc, but since i don't use a dataset to populate my
DataGridView, i cannot extract the data to xml with the WriteXML method.. so
what i was looking for was a way to extract a DataSet out of the
DataGridView eventough it was not bounded, i know this doesn't makse sense..
let me explain a bit..

I create rows programatically , say after 10 rows have been created, i want
to save that information to a file so that next time my application runs,
the datagridview is populated again.. i think from the looks of it, there is
no easy way to do it than to iterate and write each row information to an
xml file and read it back to re-create the rows when the application starts
up..

i was thinking there was an easy method to export/serialize the data out a
datagridview..

any suggestions?

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
A DataGridView is a user interface component, not a data component. It is
bound to a DataSet by means of a BindingSource, which relates the data in a
particular table or view in the DataSet to the DataGridView. The
DataGridView then uses the BindingSource to display the data in a
meaningful way. Therefore, you don't want to serialize a DataGridView at
all; you want to serialize the data that is contained (or rather
"displayed" ) in it. This would entail serializing the DataSet.

As to why you were "not able to get it," that is the crux of the problem,
and cannot be answered until you describe exactly what you tried, and what
the results were.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

"Henok Girma" <no****@spamfre e.com> wrote in message
news:SWeRf.8196 02$x96.730159@a ttbi_s72...
anyone?

"Henok Girma" <no****@spamfre e.com> wrote in message
news:Qd5Rf.8179 25$x96.97819@at tbi_s72...
What i wanted to store was the value of those items, while i can iterate
create line by line the xml file, i would much rather use the dataset
and WriteXml method, but for some reason i was not able to do so for an
unbound DataGridView. the user creates the rows and sets the values,
then when they click save, i want to output all the data to an XML file,
idealy, i want to extract the DataSet of the DataGridView to save it to
XML using the WriteXML method mentioned, but i was not able to get it.

Do i make sense?

"A.Kahtava" <ka*****@gmail. com> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.com.. .
Do you really want to save a TextBox, ComboBox and data to an XML file?

Generally DataGrids are displaying data from a DataSet, you can save
the data within a DataSet through the DataSet.WriteXm l() method.

The DataSet Class:
http://msdn.microsoft.com/library/de...ClassTopic.asp



Mar 13 '06 #7
I might have some sample to help. If you don't mind can you tell me where to
send sample code?

"Henok Girma" wrote:
ok, now we are getting somewhere.. i understand about the DataSet and the
bindingsource etc, but since i don't use a dataset to populate my
DataGridView, i cannot extract the data to xml with the WriteXML method.. so
what i was looking for was a way to extract a DataSet out of the
DataGridView eventough it was not bounded, i know this doesn't makse sense..
let me explain a bit..

I create rows programatically , say after 10 rows have been created, i want
to save that information to a file so that next time my application runs,
the datagridview is populated again.. i think from the looks of it, there is
no easy way to do it than to iterate and write each row information to an
xml file and read it back to re-create the rows when the application starts
up..

i was thinking there was an easy method to export/serialize the data out a
datagridview..

any suggestions?

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
A DataGridView is a user interface component, not a data component. It is
bound to a DataSet by means of a BindingSource, which relates the data in a
particular table or view in the DataSet to the DataGridView. The
DataGridView then uses the BindingSource to display the data in a
meaningful way. Therefore, you don't want to serialize a DataGridView at
all; you want to serialize the data that is contained (or rather
"displayed" ) in it. This would entail serializing the DataSet.

As to why you were "not able to get it," that is the crux of the problem,
and cannot be answered until you describe exactly what you tried, and what
the results were.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

"Henok Girma" <no****@spamfre e.com> wrote in message
news:SWeRf.8196 02$x96.730159@a ttbi_s72...
anyone?

"Henok Girma" <no****@spamfre e.com> wrote in message
news:Qd5Rf.8179 25$x96.97819@at tbi_s72...
What i wanted to store was the value of those items, while i can iterate
create line by line the xml file, i would much rather use the dataset
and WriteXml method, but for some reason i was not able to do so for an
unbound DataGridView. the user creates the rows and sets the values,
then when they click save, i want to output all the data to an XML file,
idealy, i want to extract the DataSet of the DataGridView to save it to
XML using the WriteXML method mentioned, but i was not able to get it.

Do i make sense?

"A.Kahtava" <ka*****@gmail. com> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.com.. .
> Do you really want to save a TextBox, ComboBox and data to an XML file?
>
> Generally DataGrids are displaying data from a DataSet, you can save
> the data within a DataSet through the DataSet.WriteXm l() method.
>
> The DataSet Class:
> http://msdn.microsoft.com/library/de...ClassTopic.asp
>



Mar 24 '06 #8
Hello! Perhaps this will help you, some code to look into:
IP.xml :
<?xml version="1.0" encoding="utf-8" ?>
<iplista>
<ip>192.168.1.1 2</ip>
<ip>192.168.1.1 3</ip>
<ip>192.168.1.1 4</ip>
<ip>192.168.1.1 5</ip>
<ip>192.168.1.1 6</ip>
<ip>192.168.1.1 7</ip>
</iplista>

Display data in dataGridview and save it:
//
string filePath = "IP.xml";

public Form1()
{
InitializeCompo nent();
ipDataset.ReadX ml(filePath);
dataGridView1.D ataSource = ipDataset;
dataGridView1.D ataMember = "ip";
}

// Update button in winForm and a textbox1 to write data to save in xml
file...
private void button2_Click(o bject sender, EventArgs e)
{
XmlTextReader reader = new XmlTextReader(f ilePath);
XmlDocument doc = new XmlDocument();
doc.Load(reader );
reader.Close();

XmlNode currNode;
XmlDocumentFrag ment docFrag = doc.CreateDocum entFragment();
if (textBox1.Text != "")
{
docFrag.InnerXm l = "<ip>" + textBox1.Text + "</ip>";
// insert the "data" node at the end of the xml file.
currNode = doc.DocumentEle ment;
currNode.Insert After(docFrag, currNode.LastCh ild);
//save the output to a file
doc.Save(filePa th);
//Update the DATAGRID_VIEW!! !!!??????
// LoadXml(filePat h);
}
else
{
MessageBox.Show ("Fyll i nått värde i textbox1");
}
}
*************** ***HOPE IT HELPS YOU ON THE WAY************ *
"M. Matsuda" wrote:
I might have some sample to help. If you don't mind can you tell me where to
send sample code?

"Henok Girma" wrote:
ok, now we are getting somewhere.. i understand about the DataSet and the
bindingsource etc, but since i don't use a dataset to populate my
DataGridView, i cannot extract the data to xml with the WriteXML method.. so
what i was looking for was a way to extract a DataSet out of the
DataGridView eventough it was not bounded, i know this doesn't makse sense..
let me explain a bit..

I create rows programatically , say after 10 rows have been created, i want
to save that information to a file so that next time my application runs,
the datagridview is populated again.. i think from the looks of it, there is
no easy way to do it than to iterate and write each row information to an
xml file and read it back to re-create the rows when the application starts
up..

i was thinking there was an easy method to export/serialize the data out a
datagridview..

any suggestions?

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
A DataGridView is a user interface component, not a data component. It is
bound to a DataSet by means of a BindingSource, which relates the data in a
particular table or view in the DataSet to the DataGridView. The
DataGridView then uses the BindingSource to display the data in a
meaningful way. Therefore, you don't want to serialize a DataGridView at
all; you want to serialize the data that is contained (or rather
"displayed" ) in it. This would entail serializing the DataSet.

As to why you were "not able to get it," that is the crux of the problem,
and cannot be answered until you describe exactly what you tried, and what
the results were.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

"Henok Girma" <no****@spamfre e.com> wrote in message
news:SWeRf.8196 02$x96.730159@a ttbi_s72...
> anyone?
>
> "Henok Girma" <no****@spamfre e.com> wrote in message
> news:Qd5Rf.8179 25$x96.97819@at tbi_s72...
>> What i wanted to store was the value of those items, while i can iterate
>> create line by line the xml file, i would much rather use the dataset
>> and WriteXml method, but for some reason i was not able to do so for an
>> unbound DataGridView. the user creates the rows and sets the values,
>> then when they click save, i want to output all the data to an XML file,
>> idealy, i want to extract the DataSet of the DataGridView to save it to
>> XML using the WriteXML method mentioned, but i was not able to get it.
>>
>> Do i make sense?
>>
>> "A.Kahtava" <ka*****@gmail. com> wrote in message
>> news:11******** **************@ z34g2000cwc.goo glegroups.com.. .
>>> Do you really want to save a TextBox, ComboBox and data to an XML file?
>>>
>>> Generally DataGrids are displaying data from a DataSet, you can save
>>> the data within a DataSet through the DataSet.WriteXm l() method.
>>>
>>> The DataSet Class:
>>> http://msdn.microsoft.com/library/de...ClassTopic.asp
>>>
>>
>>
>
>


Jun 8 '06 #9

Hi , I understand what you're trying to do, and I agree it seems
strangely clunky to move data back from the edited DataGridView. Given
the excellence elsewhere it seems odd that we can't just say:

dataGridView1.W riteXmlData(fil epath/StreamWriter object)

or .WriteUpdate

I wish I could be of more help ; perhaps this will spark a response
that does help more though :-)

N


*** Sent via Developersdex http://www.developersdex.com ***
Jun 16 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7203
by: JeffGoneMad | last post by:
Hi, I'm kind of a newbie to VB, so I hope this doesn't seem too trivial. I have a problem with the DataGridView control. I can find all kinds of stuff about populating data in a DataGridView control, but I haven't found a way to save the data on program exit. There must be a way, after all, you can't expect people to re-input all the...
0
1802
by: Diogo Alves - Software Developer | last post by:
Greetings Everyone! Here's my issue, I have a datagridview, and I'm already using currentCellChanged Event. What I want to do is... before the currentCellChanged, check if the user any changes do the details panel for that row, and ask him if he wants to save the changes on the details, then rebind the grid. Currently it gives me an...
6
1873
by: alexia.bee | last post by:
Hi all, I am new to C# so please bear me :). I have an app which uses datagridview. it has 8 columns. I also have struct which has 8 members(the same as the datagridview). when I add row to the gridview, i add the same data to this staruct and then add this struct instance to a list. the app creates more then one file with different...
1
2000
by: Masterfrier | last post by:
Hi guys! I have a DataGridView populated from various textfiles. I need to be able to save the content from this datagridview as an XML file. How can this be done without using a dataset from a DB?? any help/hint would be appreciated
0
1181
by: Cat | last post by:
Hi. What I am trying to do is very simple, but it somehow didn't work. I had created a table in a .MDB file, That table had 5 fields and one of which was the primary key. I added a DataGridView and set the binding source to that table. Visual Studio generated bunch of adapter classes. I didn't want to let users directly add rows so I...
5
2417
by: GS | last post by:
I Google search for answer to detected changes to the current row in detail view of a windows form ( not datagridview), so far I have not got the right search term to get me the answer, certainly I found lots on datagridview and ..net asp form. Is there an easy way to detect if the current record has been changed during row leave or somehow...
0
1474
by: Ryan Liu | last post by:
I found DataGridView in .NET 2.0 has a bug, or maybe I used it in a wrong way, just try to confirm with you guys: I have a checkbox column in it, and a save button on the form try to save changes made by this checkbox column. But the state of last checkbox is always not saved, unless I click somewhere else on the form. //all of these...
2
1621
by: veer | last post by:
hi i want to save the value which i write in the datagridview cells how can i do actually i want to insert the value into the ms acees table by writting the values in gridview cells and then click on save button it saves into should save into the ms access table thanks in advance
4
2846
by: Christian | last post by:
Hi, how i can save the rows in a DataGridView in c# 2008? i haven't a DB but only datagridview...
0
7658
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
7579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7876
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7630
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7941
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2077
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.