We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Problem in SaveCellInfo

Hello
I use GridControl based custom grid in UserControl. I want to fire an event with original value (from my datasource) and new value (set in grid) in event SaveCellInfo. If someone refuses changes (event result is false) I need to keep the original value - so I push it into e.Style.CellValue.
Problem is when somebody in the handler method throws e.g. MessageBox (with YES/NO confirmation). The cell looses focus and since then it doesn't matter whatever is in CellValue because the last edited value stays in the cell displayed. Model data is OK. Only problem is with the displayed value which doesn't match the CellValue no matter of CellType (TextBox, ComboBox, ...). If there's no MessageBox to show up everything works fine. Any suggestions?


3 Replies

AS Asarudheen S Syncfusion Team September 27, 2011 04:28 AM UTC

Hi Michal,

Thank you for your interest in Syncfusion products.

Please make use of “ e.Handled = true” in the “SaveCellInfo” event to avoid this problem. It will retained focus to the samec cell if the save action is failed.

Please let me know if I misunderstood your query.

Regards,
Asarudheen.




MR Michal Recka October 4, 2011 06:27 AM UTC

Thank you for your answer. I'll try to explain it with some code sample:

private void grid_SaveCellInfo(object sender, GridSaveCellInfoEventArgs e)
{
CellInfo cell = e.Style.Tag as CellInfo;
if (cell == null || cell.CellProperty == null)
return;

if (!SetPropertyValue(cell.CellProperty, e.Style.CellValue, true, true))
{
e.Style.CellValue = cell.CellProperty.Value;
}

e.Handled = true;
grid.RefreshRange(GridRangeInfo.Cell(e.RowIndex, e.ColIndex));
}


private bool SetPropertyValue(Property property, object value, bool sendValueChangingEvent, bool sendValueChangedEvent)
{
if (property == null)
throw new ArgumentException("Property can not be null", "property");

if (property.ValueType != typeof(object))
{
try
{
value = Convert.ChangeType(value, property.ValueType);
}
catch (Exception ex)
{
Errors.Push(new ErrorStackItem(InfoTypes.Error, Core.StrFormat(Resources.errConvertToType, property.ValueType.FullName), ex, "SetPropertyValue", property, value));
}
}

if ((value == null && property.Value != null) || (value != null && !value.Equals(property.Value)))
{
PropertyValueChangeEventArgs e = new PropertyValueChangeEventArgs(property.Name, property.Value, value);
if (sendValueChangingEvent && PropertyValueChanging != null && !PropertyValueChanging(this, e))
return false;

property.Value = value;
if (sendValueChangedEvent && PropertyValueChanged != null)
PropertyValueChanged(this, e);
}
return true;
}

Problem is only when somebody catches an event PropertyValueChanging (my own event) and for example wants user to decide if he wants to accept the change in MessageBox. It doesn't matter if he accepts or not. The TEXT value of cell remains the last displayed text althought the CellValue may be already completely different. (I use also grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) with e.Handled = true) Only thing that seems to help is Refresh() of whole grid which is quite overkill.



AS Asarudheen S Syncfusion Team October 10, 2011 06:32 AM UTC

Hi Michal,

Thanks for the update.

We could not able to obtain your actual intention .Could you please share us more information probably a sample or screen shot which shows your problem,which will be more helpful for us to provide a better solution to you?

Appreciate any additional information.

Regards,
Asarudheen.





Loader.
Live Chat Icon For mobile
Up arrow icon