DataGridView WriteXml() not saving
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: DataGridView WriteXml() not saving

Hybrid View

  1. #1
    Join Date
    Jul 2010
    Posts
    82

    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.

  2. #2
    Join Date
    Jul 2010
    Posts
    82

    Re: DataGridView WriteXml() not saving

    95 views and none could help - anyway, I'll find out and post it here for others.

  3. #3
    Join Date
    Jan 2011
    Posts
    11

    Re: DataGridView WriteXml() not saving

    Code?

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    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.

  5. #5
    Join Date
    Jul 2010
    Posts
    82

    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!!

  6. #6
    Join Date
    Jul 2010
    Posts
    82

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center