How do I save changes to my datasource when swapping datasources out of my DGV?-VBForums
Results 1 to 4 of 4

Thread: How do I save changes to my datasource when swapping datasources out of my DGV?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2016
    Posts
    66

    How do I save changes to my datasource when swapping datasources out of my DGV?

    I have two datasources that i switch out of my datagridview, but when i change between the two the changes i've made to either one are not saved... How do I accomplish such? For example, I change the forcolor of certain rows in one datasource and when i swap back and forth the color is back to default.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,597

    Re: How do I save changes to my datasource when swapping datasources out of my DGV?

    It's not that the colour is back to the default. It's that changing the data source causes all the existing rows to be removed and new ones added. You've never set those new rows to anything other than the default colour so why would they be anything but the default colour? This is why it's best to use events of the grid to do formatting like this. That way, it doesn't matter what changes you make to the grid as all the correct formatting will be reapplied dynamically.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2016
    Posts
    66

    Re: How do I save changes to my datasource when swapping datasources out of my DGV?

    I am periodically changing certain rows to the color red, as well as selecting them in a checkbox column. I should elaborate on this. The records in my DGV will be manipulated based off a search criteria I have built in another form. This will lead to the rows changing in a variety of ways up to and including what I have previously described (color, checkboxcolumn, etc.)
    Last edited by Christhemist; Nov 29th, 2016 at 05:37 PM.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,597

    Re: How do I save changes to my datasource when swapping datasources out of my DGV?

    You will need to either build a list of criteria that a row must match in order to be highlighted and then process those criteria on the appropriate event of the grid, which ensures that all matching rows will always be highlighted no matter what else you do, or else you'll need to process the new rows that get added to highlight those that need it after resetting the data source.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.