I have an ultragrid with a double click event:
void grdMain_DoubleClickRow(object sender, DoubleClickRowEventArgs e) { EditNotes(e.Row); }
private void EditNotes(UltraGridRow pRow){ try { var frm = new FrmDialogEditNotes { Notes = pRow.Cells["Notes"].Value.ToString(), NoteType = pRow.Cells["Description"].Value.ToString(), VersionNumber = ApplicationSettings.ActiveScenarioNumber, WindowState = FormWindowState.Maximized, SetSaveDisabled = false };
if (frm.ShowDialog(this) != DialogResult.OK) return;
pRow.Cells["Notes"].Value = frm.Notes; } catch (Exception ex) { ExceptionPolicy.HandleException(ex, "Exception Policy"); }}
WHen I double click the cell I get my notes dialog and I make some notes and click the save button and when it exits it tries to set the cells value but I get an error "Specified cast is not valid"
The underlying data is an NVARCHAR(MAX) and there are no NULLs for the notes record. So I am at a loss. Frm.Notes is string property.
Any thoughts?
I solved it... I forgot about the grdMain_AfterCellUpdate gets called... the problem was in that event. I have some code there to do certain things and one of them was to cast the cell value to a decimal to do some calcs based on another cell. So I added an IF check to bounce out if the cell was "Notes" Everything works fine now.
Oops! Thanks for your help though...
I should mention I am using version 13.1.
Yes I have tried to set the same string directly to the cell value.
private void EditNotes(UltraGridRow pRow)
{
try
var dType = pRow.Cells["Notes"].Column.DataType;
pRow.Cells["Notes"].Value = "sdfgsdfg";
}
catch (Exception ex)
var x = 0; // for breakpoint
(dType returns --> Name = "String" FullName = "System.String")
I have a test container that replicates this same problem.... using the same stored procedure to return my data. ( Notes NVARCHAR(MAX),)
, ISNULL(Notes,'') AS [Notes]
They all have the same result "Specified cast is not valid."
If I put a break point in the "catch" and look at the value for the cell... it contains the "sdfgsdfg" value.
One other thing I have noticed is that if I do the same row again it works. But only because it already has a value I suspect.
Hello ,
Have you tried to set same string directly to the cell value instead going through the dialog form ? What is the result ? What is the string that you trying to add to this cell ? What is the type of the UltraWinGridColumn (pRow.Cells["Notes"].Column.DataType) ? have you tried to isolate this in a separate sample ?
I am waiting for your feedback.