Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Check if changes exist?

Check if changes exist?

Scheduled Pinned Locked Moved Visual Basic
question
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr Oizo
    wrote on last edited by
    #1

    Hi I want to disable/ enable my save all button if changes exist in the datagridview. Where would I need to put the code and what does that code typically look like? Thanks in advance. Im aware that I have to set the button to "enabled = false" but where? and how do I check for changes? Mr Oizo

    V D 2 Replies Last reply
    0
    • M Mr Oizo

      Hi I want to disable/ enable my save all button if changes exist in the datagridview. Where would I need to put the code and what does that code typically look like? Thanks in advance. Im aware that I have to set the button to "enabled = false" but where? and how do I check for changes? Mr Oizo

      V Offline
      V Offline
      Vimalsoft Pty Ltd
      wrote on last edited by
      #2

      hi Try this

              If DataSet111.HasChanges = True Then
               btnSave.Enabled = true
               else 
                btnsave.Enabled = False 
              end if 
      

      hope it helps

      Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

      1 Reply Last reply
      0
      • M Mr Oizo

        Hi I want to disable/ enable my save all button if changes exist in the datagridview. Where would I need to put the code and what does that code typically look like? Thanks in advance. Im aware that I have to set the button to "enabled = false" but where? and how do I check for changes? Mr Oizo

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        Handle the DataGridView's CurrentCellDirtyStateChanged event. Then the code would probably look something like:

        If DataGridView1.IsCurrentCellDirty Then
            ' Enable save changes button.
        End If
        

        Do NOT put in code to disable the button! Once a cell is dirty, consider the entire dataset dirty, even if this cell is changed back to it's original value!

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        M 1 Reply Last reply
        0
        • D Dave Kreskowiak

          Handle the DataGridView's CurrentCellDirtyStateChanged event. Then the code would probably look something like:

          If DataGridView1.IsCurrentCellDirty Then
              ' Enable save changes button.
          End If
          

          Do NOT put in code to disable the button! Once a cell is dirty, consider the entire dataset dirty, even if this cell is changed back to it's original value!

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          M Offline
          M Offline
          Mr Oizo
          wrote on last edited by
          #4

          Ok thanks for the help. you say I shouldn't disable the save button at all but I seem to get data cncurrency errors in my code when I save the same values twice. What happens is that an autonumber is generated for each song in my song library whena new song is added and when i call savechanges it gives me a concurrency error if i hit save twice in a row. so I just wanna disable that button when they have already pressed save and if they edit further then re-enable the button. Any ideas where to put the code? Mr Oizo

          D 1 Reply Last reply
          0
          • M Mr Oizo

            Ok thanks for the help. you say I shouldn't disable the save button at all but I seem to get data cncurrency errors in my code when I save the same values twice. What happens is that an autonumber is generated for each song in my song library whena new song is added and when i call savechanges it gives me a concurrency error if i hit save twice in a row. so I just wanna disable that button when they have already pressed save and if they edit further then re-enable the button. Any ideas where to put the code? Mr Oizo

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Mr Oizo wrote:

            but I seem to get data cncurrency errors in my code when I save the same values twice.

            OK. Obviously, you can reset the save button AFTER the changes are saved. Come on, think!!

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            M P 2 Replies Last reply
            0
            • D Dave Kreskowiak

              Mr Oizo wrote:

              but I seem to get data cncurrency errors in my code when I save the same values twice.

              OK. Obviously, you can reset the save button AFTER the changes are saved. Come on, think!!

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              M Offline
              M Offline
              Mr Oizo
              wrote on last edited by
              #6

              I think i have a big problem with my program.I have sat for 3 weeks with this data concurrency error and I can't fix it. it is happening in a project i'm writing for my thesis and at the moment i'm gonna fail just because this is stopping me from continuing with the rest of my project. the problem is that I can add data to a dataset but as soon as I try to edit the newly added data and save a data concurrency error appears(o records updated out of the expected 1 record(or similar to that)). I have read tons of articles and still can't find the problem. It's a single user environment, my dataset tables and database tables have the same field types and everything. the update statement looks fine. the only thing that i can assume is wrong is something to do with the fact that i have a datagridview and several textboxes bound to the underlying dataset and when I call "saveChanges" it tries to save the values from both the textbox for the column and the datagridview for the column. the only code used by my textboxes and datagrid is databinding code eg: modbdaSongNewest2.ClearBeforeFill = True modbdaSongNewest2.Fill(DsLibraryNewest2.Song) ' bindingSong is a bindingsource object bindingSong.DataSource = DsLibraryNewest2 bindingSong.DataMember = "Song" dgSongProperties.DataSource = bindingSong txtArtist.DataBindings.Add("Text",bindingSong, "Artist",_ True, DataSourceUpdateMode.OnPropertyChanged) When adding new songs to the library I use the Openfiledialog and run a for loop for each file that was selected and add rows using this code which is pretty standard: Dim FileInfo As System.IO.FileInfo ' This variable will hold the selected file info Dim drCurrentSong As dsLibraryNewest2.SongRow If Not (dlgOpenFile Is Nothing) Then For i = 0 To dlgOpenFile.FileNames.GetUpperBound(0) FileInfo = My.Computer.FileSystem.GetFileInfo(dlgOpenFile.FileNames(i)) ' This will retrieve the foldername for the file Dim folderPath As String = FileInfo.DirectoryName ' MsgBox(folderPath) ' This will retrieve file name for the file Dim fileName As String = FileInfo.Name 'MsgBox(fileName) ' This will retrieve the full path of the file Dim absolutePath As String = FileInfo.FullName ' MsgBox(absolutePath)

              D 1 Reply Last reply
              0
              • M Mr Oizo

                I think i have a big problem with my program.I have sat for 3 weeks with this data concurrency error and I can't fix it. it is happening in a project i'm writing for my thesis and at the moment i'm gonna fail just because this is stopping me from continuing with the rest of my project. the problem is that I can add data to a dataset but as soon as I try to edit the newly added data and save a data concurrency error appears(o records updated out of the expected 1 record(or similar to that)). I have read tons of articles and still can't find the problem. It's a single user environment, my dataset tables and database tables have the same field types and everything. the update statement looks fine. the only thing that i can assume is wrong is something to do with the fact that i have a datagridview and several textboxes bound to the underlying dataset and when I call "saveChanges" it tries to save the values from both the textbox for the column and the datagridview for the column. the only code used by my textboxes and datagrid is databinding code eg: modbdaSongNewest2.ClearBeforeFill = True modbdaSongNewest2.Fill(DsLibraryNewest2.Song) ' bindingSong is a bindingsource object bindingSong.DataSource = DsLibraryNewest2 bindingSong.DataMember = "Song" dgSongProperties.DataSource = bindingSong txtArtist.DataBindings.Add("Text",bindingSong, "Artist",_ True, DataSourceUpdateMode.OnPropertyChanged) When adding new songs to the library I use the Openfiledialog and run a for loop for each file that was selected and add rows using this code which is pretty standard: Dim FileInfo As System.IO.FileInfo ' This variable will hold the selected file info Dim drCurrentSong As dsLibraryNewest2.SongRow If Not (dlgOpenFile Is Nothing) Then For i = 0 To dlgOpenFile.FileNames.GetUpperBound(0) FileInfo = My.Computer.FileSystem.GetFileInfo(dlgOpenFile.FileNames(i)) ' This will retrieve the foldername for the file Dim folderPath As String = FileInfo.DirectoryName ' MsgBox(folderPath) ' This will retrieve file name for the file Dim fileName As String = FileInfo.Name 'MsgBox(fileName) ' This will retrieve the full path of the file Dim absolutePath As String = FileInfo.FullName ' MsgBox(absolutePath)

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                Guy, I can't tell you how to unravel this because your code is a pile of spaghetti. What we tell you to change in one place breaks something in another. We can't see the entire picture of what's going on from a few code snippets. This is a much larger design issue than it is a "simple fix" because you forgot something.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007

                M 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  Guy, I can't tell you how to unravel this because your code is a pile of spaghetti. What we tell you to change in one place breaks something in another. We can't see the entire picture of what's going on from a few code snippets. This is a much larger design issue than it is a "simple fix" because you forgot something.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007

                  M Offline
                  M Offline
                  Mr Oizo
                  wrote on last edited by
                  #8

                  Thanks Mr Oizo

                  1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    Mr Oizo wrote:

                    but I seem to get data cncurrency errors in my code when I save the same values twice.

                    OK. Obviously, you can reset the save button AFTER the changes are saved. Come on, think!!

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007

                    P Offline
                    P Offline
                    Patrick Etc
                    wrote on last edited by
                    #9

                    Dave Kreskowiak wrote:

                    Come on, think!!

                    Pbbbbbbbbt. Why would they do that, that's why they're asking questions in the CP forums... Sigh..


                    The early bird who catches the worm works for someone who comes in late and owns the worm farm. -- Travis McGee

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups