none
Updating data in DataGridView RRS feed

  • Question

  • I'm populating a DataGridView from a table in the Load() event, which works.  I want to call a separate method to display data after any data has been changed (delete/insert/update).  Can I use the existing datagridview object to display updated data or do I need to create new objects (form/datagridview/columns) to display updated data?  
    Tuesday, April 25, 2017 6:23 PM

Answers

  • Solved.  Pass instance of form1 (this) to form2.  Then, after updating table, used passed instance of form1 to call method to load data in form1.
    Friday, February 16, 2018 11:49 PM

All replies

  • Hi RichardDunneBSc,

    The forums have had major problems the last few days. Most posts, including this one, did not show in any view of threads. We have just seen this question.

    This forum is for questions and discussions about the Visual Studio IDE, as your issue is more related to the Windows Forms. I will move this question to that forum for better support.
    Thanks for your understanding and cooperation.


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, April 27, 2017 5:29 AM
  • Hello,

    First off, to get changes see my MSDN code samples. In the samples you will note I get each change type separately as this is a condition of "DataTable.GetChanges method" where the states are

    With that in mind, using my code (which is in a class project that you can add to your solution) you can get all changes then decide how to display them to the user. If you loaded the DataGridView via a DataTable where the primary key is in that table (does not have to display) then you can find that record and perhaps mark it color-wise or combine the tables obtained from GetChanges into another DataGridView where I would add a column to the merged DataTable were the column might signify what type of change the row represents e.g. if the row was added the value for that column would be "added" etc.

    How you display the changes be it separately or combined is your choice.

    Hope this helps.

    Lastly, for real time changes see my other MSDN code sample using DataTable events.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, April 27, 2017 12:52 PM
    Moderator
  • I'm populating a datagridview in the form Load() method.  Displaying updated data by calling a separate method, but having pretty much the same code as in the Load() method.  My worry was the by creating the object again, I was updating a different object because the datagridview isn't showing the updated value(s).  Both datagridview objects have the same name, but only one datagridview ever appears on the form.  Stepping through the code, the cell(s) being updated show the updated value(s), but display the old value(s) when the form opens.  The SQLReader is suddenly behaving despite hasRows = true and Results View being Empty: Enumeration yielded no results.  Perplexing.
    Friday, April 28, 2017 4:10 PM
  • Solved.  Pass instance of form1 (this) to form2.  Then, after updating table, used passed instance of form1 to call method to load data in form1.
    Friday, February 16, 2018 11:49 PM