Check if changes exist?
-
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
-
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
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
-
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
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 -
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, 2007Ok 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
-
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
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 -
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, 2007I 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)
-
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)
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 -
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 -
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, 2007Dave 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