Completed
Last Updated: 22 Jun 2021 17:34 by ADMIN
Release R3 2021
Antti
Created on: 07 Jun 2021 14:58
Category: GridView
Type: Bug Report
0
RadGridview: Exception when colapsing a row that has a RadTextBoxControlEditor open
I have a RadGridView that has expandable rows. If I expand the row, start editing an editable cell and then, without committing the edit (by pressing enter or clicking away from the cell), collapse the row, the program crashes with roughly the following stack trace:


Stack Trace:
   at System.Collections.ArrayList.BinarySearch(Int32 index, Int32 count, Object value, IComparer comparer)
   at Telerik.WinControls.UI.TextBoxWrapPanel.BinarySearch(LineInfo line, IComparer comparer)
   at Telerik.WinControls.UI.TextBoxNavigator.GetPositionFromOffset(Int32 offset)
   at Telerik.WinControls.UI.RadTextBoxControlElement.Select(Int32 start, Int32 length)
   at Telerik.WinControls.UI.RadTextBoxControlEditor.EndEdit()
   at Telerik.WinControls.UI.GridViewEditManager.EndEditCore(Boolean validate, Boolean cancel)
   at Telerik.WinControls.UI.GridViewEditManager.CloseEditor()
1 comment
ADMIN
Nadya | Tech Support Engineer
Posted on: 07 Jun 2021 15:09

Hello, Antti,

To work around this problem you can create a custom RadTextBoxControlEditor:

public RadForm1()
{
    InitializeComponent();
    this.radGridView1.EditorRequired += this.RadGridView1_EditorRequired;

}

private void RadGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
{
    if (e.EditorType == typeof(RadTextBoxEditor))
    {
        e.Editor = new MyEditor();
    }
}
public class MyEditor: RadTextBoxControlEditor
{
    protected override RadElement CreateEditorElement()
    {
        return new MyRadControlEditorElement();
    }
}
internal class MyRadControlEditorElement : RadTextBoxControlElement
{
    protected override void CreateChildElements()
    {
        base.CreateChildElements();

        this.Navigator = new MyTextBoxNavigator(this);

    }

    protected override TextBoxViewElement CreateViewElement()
    {
        return new MyTextBoxViewElement();
    }
}

internal class MyTextBoxNavigator : TextBoxNavigator
{
    public MyTextBoxNavigator(RadTextBoxControlElement textBoxElement) : base(textBoxElement)
    {
    }

    public override bool Select(TextPosition start, TextPosition end)
    {
        if (start != null && start.TextBlock == null)
        {
            return false;
        }

        return base.Select(start, end);
    }

    public override TextPosition GetPositionFromOffset(int offset)
    {
        if (offset < 0)
        {
            throw new ArgumentOutOfRangeException("offset");
        }

        if (offset > this.TextBoxElement.TextLength)
        {
            offset = this.TextBoxElement.TextLength;
        }

        TextBoxViewElement layoutPanel = this.TextBoxElement.ViewElement;
        LineInfo line = layoutPanel.Lines.BinarySearchByOffset(offset);

        if (line == null)
        {
            return null;
        }

        ITextBlock textBlock = layoutPanel.BinarySearchTextBlockByOffset(line, offset);
        int characterPosition = offset;
        if (textBlock != null)
        {
            characterPosition -= textBlock.Offset;
        }
        TextPosition position = new TextPosition(line, textBlock, characterPosition);
        return position;
    }

}
internal class MyTextBoxViewElement : TextBoxViewElement
{
    protected override ITextBlock BinarySearch(LineInfo line, IComparer comparer)
    {
        if (this.Children.Count == 0)
        {
            return null;

        }
        
        return base.BinarySearch(line, comparer);
    }
}

I hope this helps. 

Regards,
Nadya
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.