I'm trying to save the updated values of an UltraGrid, and I have one variable for each column in the grid. Despite calling ugModules.Update(), and updating the row that is being iterated over, the variable values are not reflecting the new values in the grid, they're always holding the values of the original data.
I also have the UpdateMode to OnUpdate in InitializeLayout, but they just aren't updating.
The grid DataSource is a DataSet that I created after running a Select query, if that helps?
This is the code:
ugModules.UpdateData()
Dim mID As Integer = 0 Dim mName As String = "" Dim numUsers As String = ""
For Each ugr As UltraGridRow In ugModules.Rowsugr.Update()
mID = ugr.Cells("ModuleID").Value mName = ugr.Cells("ModuleName").Value numUsers = ugr.Cells("NumberUsers").Value
Yet, those variables are always reflecting the old values. I've also tried without ugr.Update(), but that made no difference?
Hi,
I'm a little confused by what you want here, but the property setting you are using seem to be the opposite of what you are trying to achieve.
It's not clear from your description exactly what changes you are making to the cell values or how you are making them. Are you setting the Value of a cell in code? Are you making changes by typing or otherwise choosing a value for the grid cell through the UI?
The Value property of a cell returns the value from the underlying data source - in this case, your DataSet. So if you enter edit mode on a cell and start typing, the Value will be the old value. If you want the text on the screen you would have to use the Text property of the cell.
The changes to a cell normally get committed to the data source when the user either leaves that cell or loses focus on the grid. But this is controlled by the UpdateMode property and since you change it to OnUpdate, it will not happen until you call UpdateData or until the BindingManager position changes. To be totally honest, the OnUpdate setting doesn't really work correctly. It was carried over from ActiveX and it's not actually a viable setting in DotNet. But it seems like the opposite of what you want, anyway. So I would not recommend using it.
Also... and maybe this is just a typo, but you mentioned calling ugModules.Update(). The actual code example is calling UpdateData. These methods are not the same thing. Update just forced a paint and will not have any effect on your data or it's commitment to the data source. UpdateData is the correct method to force the data to be committed to the Data Source.
Hi Mike,
Thanks for the response.
The changes are being made by typing in values into the grid cells, or choosing an item in a drop down list in the case of one of the columns, so it's all done manually by the user.
I've changed the variable declaration to use the column .Text property, but still the variables are being assigned the original value.
This is also the case after taking out the UpdateData setting, too.
The UpdateData method is the one I am using, I meant to say I had tried both, but I'm currently calling UpdateData.
My code now is
For Each ugr As UltraGridRow In ugModules.Rows
mID = ugr.Cells("ModuleID").Text mName = ugr.Cells("ModuleName").Text numUsers = ugr.Cells("NumberUsers").Text
sql = "UPDATE dbo.tblModules SET ModuleID = ?, ModuleName = ?, NumberUsers = ? WHERE ContractID = ?" cmd = New OleDbCommand(sql, con) cmd.Parameters.Add("@mid", OleDbType.Integer).Value = mID cmd.Parameters.Add("@mname", OleDbType.VarChar).Value = mName cmd.Parameters.Add("@numusers", OleDbType.VarChar).Value = numUsers cmd.Parameters.Add("@conID", OleDbType.Integer).Value = CID cmd.ExecuteNonQuery() Next
Is there anything else it could be?
Yep, that would do it. :)
I debugged more thoroughly and found that the cause was because the dataset was being reloaded in one of the other UltraGrid events, which was being called during the save process. I've taken it out and it's now working fine.
Thanks.
Hi David,
Well, I'm stumped. Unless you are referencing the wrong row or the wrong grid control, I don't see how this is possible. If you are seeing the value on the screen, the Text property has to return what you are seeing. The Value comes from the underlying data source, but once you leave the row, this has to be updated, as well.
Can you post a small sample project that demonstrates the behavior? If so, I will be happy to take a look and I'm sure I can figure out what's wrong.