-
January 3rd, 2011, 05:31 PM
#1
DataGridView WriteXml() not saving
I have simple datagridview that saves each line as a record to XML as they are entered. I use the CellEndEdit event to call the WriteXml() of the gridview which should save the coulmns as nodes in the XML. But, it does not do so for the first record!!
When I create another record and then do some mouse clicks navigation or press the movefirst, movelast buttons in the binded navigator, then it saves to the XML! It obviously is not finding the data to be saved for the first record - any help would be greatly appreciated.
Thank you,
CT.
-
January 4th, 2011, 02:55 PM
#2
Re: DataGridView WriteXml() not saving
95 views and none could help - anyway, I'll find out and post it here for others.
-
January 5th, 2011, 05:06 PM
#3
Re: DataGridView WriteXml() not saving
-
January 5th, 2011, 06:10 PM
#4
Re: DataGridView WriteXml() not saving
Yeah, the quality of the question is proportional to the quality of the responses. We need to see your code.
-
January 5th, 2011, 06:52 PM
#5
Re: DataGridView WriteXml() not saving
Okay! The code does exactly this - there is a datagridview thats has few columns like Name, Description and say DateTime field. This gridview is bound to a BindingSource object that is in turn bound to a Dataset dsTodo. This dataset maps to a table called todo which has the columns stated above as its columns as well.
And the gridview is has a binding navigator as well. Now when the user enters a description in the grid view and presses Enter, I want it to save to XML. It does save, but not for the first record!!
private void dgvwTodoList_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
dsTodo.WriteXml(m_sTodoXmlPath); //path where xml file is stored
}
So, the user can create a new item by pressing the + sign in the binding navigator control - its a predesigned control that comes with Microsoft pack so I have not coded anything for it.
When the user creates few records . then its saved perfectly, but if its just one or two, then it does NOT save at all. The reason I find is that when you click around in the gridview and use the Move Next, Previous buttons it saves perfectly. But, when its just one record, it does NOT save!!
-
January 6th, 2011, 07:37 PM
#6
Re: DataGridView WriteXml() not saving
Okay, I narrowed down the problem and fixed it - with a weird side effect.
Calling bindingsource1.EndEdit() before calling WriteXml() will make sure the rows are saved and they dont disappear as many coders have faced using this. Search in Google - Microsoft gives a vague explanation for it in Social MSDN site but that doesnt work anyway.
The weird sideffect is once the code is executed like this:
dsTodo.WriteXml(m_sTodoXmlPath); //Dataset for ToDo table writes to the XML path
bndSrcCategories.EndEdit();
In the gridview, when I try to type in the new row , it acts like the "INSERT" key has been pressed - meaning the chars flip - whatever I type replaces the characters in there - so it lets me type only 1 character anytime as that gets replaced when I type the next!!
Any help would be nice - thanks.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|