Showing a subeditor as editing finishes

Posted by: garethclay on 8 September 2017, 12:52 pm EST

  • Posted 8 September 2017, 12:52 pm EST

    Hi there,

    I'm trying to implement a custom cell type which allows users to select values from a list. One way of doing this is to click a button we're displaying at the right of the cell, which pops up the list of values as a SubEditor through IsReservedLocation. That bit works fine. The bit I'm struggling with is the alternative way we'd like users to be able to enter values. The cell also accepts text. If the user enters a string that is in the list, then we accept that value when he/she presses return or moves to another cell. However if the user-entered string isn't in the list, then we want to show our list of values again - this time filtered using the string the user entered. If the user chooses a value from that list then we update the object in our data model, otherwise if the user closes the subeditor or moves to a different cell then we want to display whatever was in the cell before the user typed an invalid value into it.

    I have an implementation that seems to work in most cases, but in others Spread behaves a little strangely. I'm assuming this is because I'm calling ShowSubEditor() in the StopEditing() method of my cell type. The code looks like this:
     
    public override bool StopEditing()
    {
    bool stopEditing = true;

    if (_selectedValue == null)
    {
    string userEnteredValue = base.GetEditorValue() as string;

    if (Utils.StringIsNotNullOrEmpty(userEnteredValue))
    {
    _selectedValue = HelperClass.FindValueByCode(userEnteredValue, _valueType);

    if (_selectedValue== null)
    {
    _valuePicker.FilterString = userEnteredValue;
    _valuePicker.FilterValues();
    ShowSubEditor();
    stopEditing = false;
    }
    }
    }

    if (_selectedValue != null)
    {
    _objectInDataModel.Value = _selectedValue;
    }

    if (stopEditing)
    {
    base.StopEditing();
    }

    return stopEditing;
    }
     
    private void _valuePicker_CloseUp(object sender, EventArgs e)
    {
    if (_valuePicker.SelectedValue != null)
    {
    _selectedValue = _counterpartyPicker.SelectedValue;
    base.SetEditorValue(_selectedValue.Code);
    }
    else
    {
    base.SetEditorValue(_objectInDataModel.ValueAsString);
    }

    StopEditing();
    }
      
    public override string Format(object obj)
    {
    string formattedValue;

    if (obj is ValueType)
    {
    formattedValue = ((ValueType) obj).ValueAsString;
    }
    else
    {
    formattedValue = base.Format(obj);
    }

    return formattedValue;
    }
    The problem I'm struggling with at the moment is that if the user types in a value that isn't in our list, and then moves off the cell while our value picker subeditor is showing, the picker appears to close but the area beneath it isn't redrawn properly so we end up with a large grey square on the screen that never disappears. I realise I could be going about this in completely the wrong way so any help you could give us would be most appreciated! :)

    Many thanks,
    Gareth
  • Replied 8 September 2017, 12:52 pm EST

    Gareth,


    I would move the code to open the SubEditor into the main project code. You need to wait for the Spread to completely exit editmode before you programatically enter editmode and show the sub editor. If you put your code in the EditModeOff event, then you can put the cell back into editmode and display the SubEditor if you like.

     
        private void fpSpread1_EditModeOff(object sender, EventArgs e)
    {
    fpSpread1.EditMode = true;
    fpSpread1.ActiveSheet.GetCellType(fpSpread1.ActiveSheet.ActiveRowIndex, fpSpread1.ActiveSheet.ActiveColumnIndex).ShowSubEditor();
    }
     
  • Replied 8 September 2017, 12:52 pm EST

    Okay, thanks Scott! We'll give that a go :)
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels