Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8331561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:27:05+00:00 2026-06-09T02:27:05+00:00

I have a WinForms screen with a DataGridView on it and Back/Next buttons. On

  • 0

I have a WinForms screen with a DataGridView on it and Back/Next buttons. On FormLoad, the grid is populated with values from an XML document. The user can then change the value of any cell in the grid. I’ve created a SaveGridValuesToXml method which updates the XML file with the updated values from the grid cells.

This mostly works okay, and I have fired the SaveGridValuesToXml method from the Leave event on the grid, so when the user clicks back or next and the grid loses focus, the save method is called.

The problem I have is that all the cell values are updated and reflected correctly in the XML file, EXCEPT for the cell which had focus when the grid loses focus. For example, in a three column grid, if I update the first, second and third cells in the first row, when the grid loses focus only the changes I made in the first and second cells are saved to my XML file.

Code examples are as follows – theLoadXmlDataIntoGridGridView() method is called when the parent form is loaded.

XmlDataDocument xmlData = new XmlDataDocument();

private void LoadXmlDataIntoGridGridView()
{        
    xmlData.DataSet.ReadXml(@"C:\testFile.xml");
    uxMappingDataGridView.DataSource = xmlData.DataSet;
    uxMappingDataGridView.DataMember = "Item";
}

private void uxBackButton_Click(object sender, EventArgs e)
{
    this.Hide();
    uxSettingsUserControl settingsScreen 
       = ParentForm.Controls["uxSettingsUserControl"] as uxSettingsUserControl;
    settingsScreen.Show();
}

private void uxNextButton_Click(object sender, EventArgs e)
{
    this.Hide();
    uxLoadScriptUserControl loadScriptScreen 
       = ParentForm.Controls["uxLoadScriptUserControl"] as uxLoadScriptUserControl;
    loadScriptScreen.Show();
}

private void uxMappingDataGridView_Leave(object sender, EventArgs e)
{
    SaveGridValuesToXml();
}

private void SaveGridValuesToXml()
{   
    xmlData.DataSet.WriteXml(@"C:\testFile.xml");
}

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:27:06+00:00Added an answer on June 9, 2026 at 2:27 am

    This is due to currently editing cell not being committed when you leave the grid by clicking on a button. 1

    To get that last value you need to force the changes to commit by calling EndEdit() on the grid.

    In the code below I call it from SaveGridValuesToXml() – in your example during the leave handler would work also, no significant difference between the two.

    private void uxMappingDataGridView_Leave(object sender, EventArgs e)
    {
        SaveGridValuesToXml();
    }
    
    private void SaveGridValuesToXml()
    {   
        uxMappingDataGridView.EndEdit(DataGridViewDataErrorContexts.Commit);
        xmlData.DataSet.WriteXml(@"C:\testFile.xml");
    }
    

    1 Not entirely sure why it works this way – personally feels like a bug but maybe someone on the DataGridView product team would say it was a feature.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Winforms DataGridView in my application. When the user selects a row
I am working on a touch screen POS in WinForms. I have a flowlayoutpanel
I have a Winforms app that allows the user to drag and drop some
I have a WinForms application, which is set to full screen mode when I
I have a WinForms application with a user control in which I change the
I have a Winforms application that the user uses to take a region based
I have a normal WinForms ToolStripDropDownButton's drop down menu that is populated dynamically. In
I have a winforms C# app. On one screen, i have two grids (infragistics)
We have a WinForms application which runs on a touch-screen on a bit of
I am working in a C# winforms project and I have a user control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.