I am trying to edit the value of a cell in an UltraGridGroupByRow. It was working fine in 2008.1. I recently upgraded the project to 2010.1 and this was one of the few things that broke compatability. I need a little help getting it working again.
The existing code that stopped working: groupByRow.Cells["Key"].Value = "Test Value";
I also tried: groupByRow.Cells["Key"].SetValue("Test Value", false);
I get the same error no matter what I do. That error is: "Column 'Key' is read only".
Does anyone know of a work around?
Thanks.
I got around my problem by manipulating the dataset before binding it to the grid. It was a little more work, but I got the overall effect I wanted.
I tried this and it still didn't work. I also updated .NET framework from 2.0 to 3.0. I tested this on a normal DataTable and I was able to do dt.AcceptChanges(); and it worked. I just can't get the UltraGrid cell to work.
DataRowView rowView = (DataRowView)groupRow.ListObject; rowView.BeginEdit(); rowView.Row["User Name"] = "Test"; rowView.EndEdit();
I also tried the code below. The grid seems to have locked down that dataset. This works with an unbound data table.
DataRowView rowView = (DataRowView)groupRow.ListObject; DataView dataView = rowView.DataView; dataView.AllowEdit = true; dataView.Table.AcceptChanges();
There are a couple of possibilities here.
1) Calling SetValue on the grid cell might be trying to mimic user interaction and therefore it will not allow you to edit a field that is ReadOnly in the grid.
If that's the case, then the solution would be to simply set the Value property on the cell. Since the code you have here appears to already be doing that, I assume you tried it and it doesn't work, so that's clearly not the issue.
2) The other possibility is that the field is read-only at the data source level and that this error is not coming from the grid, but is instead coming from your data source. Clearly that would not have changed simply by upgrading the Infragistics controls, but perhaps something else has changed in addition to the upgrade?
You could test this by trying to update the value in the data source directly instead of in the grid. What you do is access groupRow.ListObject. This will return the underlying data object that the row represents. So if you are binding to a DataSet/DataTable, this will return a DataRowView and you can get the Row from that and try to update the field(s) of that row directly.
You're right, it is a normal UltraGridRow. Is there a way to set the value of a cell on a normal row in 2010.1? Nothing I am trying is working.
Nothing has changed since 2008.1.
As you can see above I have tried .Value = value (original code), .SetValue(), and changing the Activation of the cell, row, and band to Activation.AllowEdit. Everything I do results in a Read only error.
I am not the original author of the code. I am just tasked with swapping the DLLs from 8.1 to 10.1 in the references. There were only 2 of our assemblies that broke due to broken comparability out of about 70. They both are due to this read only error from trying to change a cell value in a grid.
I thought it would be an easy fix, but I am stumped.
Here is the original code:
foreach (UltraGridRow row in ultraGridBatch.Rows) { UltraGridGroupByRow rowGroup; if (row.IsGroupByRow) { rowGroup = (UltraGridGroupByRow)row; rowGroup.Description = rowGroup.Value.ToString(); groupByRows = rowGroup.Rows; foreach (UltraGridRow groupRow in groupByRows) groupRow.Cells["User Name"].Value = Convert.ToInt32(groupRow.Cells["Batch"].Value).ToString("000") + " " + groupRow.Cells["Description"].Value.ToString(); } }
Hi,
As far as I know, the GroupByRow doesn't even have a cells collection. So I don't see how this code could ever have worked. Attempting to reference the Cells collection on a GroupByRow will result in a NullReferenceException. The Cells property is hidden from Intellisense and always returns null.