Table Tab Stops with Read Only Ranges

6 posts, 0 answers
  1. Chris
    Chris avatar
    5 posts
    Member since:
    Jan 2014

    Posted 31 Mar 2014 Link to this post

    Hi,

    I have a table that uses read only ranges for the first cell in each column and row to prevent user input. I have an issue with the tab stopping not entering the last cell of each row but if I tab again it tabs to the next row. This is due to starting my read only ranges in these cells in order to make the first cell in each row completely non-editable, if I remove them it works fine.

    Is there any way to bring the tab stop back to these cells or an alternative solution to making my headers read only?

    Here's the code I'm using to generate the table using two string arrays for the definition:

    01.Table table = new Table();
    02.table.StyleName = RadDocumentDefaultStyles.DefaultTableGridStyleName;
    03.TableRow headerRow = new TableRow();
    04.TableCell cornerCell = new TableCell();
    05. 
    06.Paragraph readOnlyPara = new Paragraph();
    07.ReadOnlyRangeStart range = new ReadOnlyRangeStart();
    08.range.AnnotationID = 1;
    09.readOnlyPara.Inlines.Add(range);
    10.cornercell.Blocks.Add(readOnlyPara);
    11.cornerCell.Background = Colors.LightGray;
    12.headerRow.Cells.Add(cornerCell);
    13.table.AddRow(headerRow);
    14. 
    15.//Add the column headers, which are an array of strings
    16.foreach (string header in headers)
    17.{
    18.    TableCell cell = new TableCell();
    19.    cell.Background = Colors.LightGray;
    20.    Paragraph p = new Paragraph();
    21.    Span text;
    22. 
    23.    //telerik paragraph cannot take empty span
    24.    if(String.IsNullOrEmpty(header))
    25.        text = new Span(" ");
    26.    else
    27.        text = new Span(header);
    28.    text.FontWeight = FontWeights.Bold;
    29. 
    30.    p.Inlines.Add(text);
    31.    cell.Blocks.Add(p);
    32.    headerRow.Cells.Add(cell);
    33.}
    34. 
    35.//questions are an array of strings
    36.for (int i = 0; i < questions.Length; i++)
    37.{
    38.    //Add the first cell of each Row
    39.    string question = questions[i];
    40.    TableRow row = new TableRow();
    41.    TableCell cell = new TableCell();
    42.    cell.Background = Colors.LightGray;
    43.    Paragraph p = new Paragraph();
    44. 
    45.    Span text = new Span(question);
    46.    text.FontWeight = FontWeights.Bold;
    47. 
    48.    p.Inlines.Add(text);
    49.    cell.Blocks.Add(p);
    50.    row.Cells.Add(cell);
    51. 
    52.    //Add the remaining cells of the row for each header
    53.    for (int y = 0; y < headers.Length; y++)
    54.    {
    55.        string header = headers[y];
    56.        TableCell answerCell = new TableCell();
    57.        Paragraph answerP = new Paragraph();
    58.        //End the read only at the start of each answering row
    59.        if (y == 0)
    60.        {
    61.            ReadOnlyRangeEnd rangeEnd = new ReadOnlyRangeEnd();
    62.            rangeEnd.AnnotationID = i + 1;
    63.            answerP.Inlines.Add(rangeEnd);
    64.        }
    65. 
    66.        //Start the read only range at the end of the answering row.
    67.        if (y == headers.Length - 1 && i != questions.Length - 1)
    68.        {
    69.            ReadOnlyRangeStart rangestart = new ReadOnlyRangeStart();
    70.            rangestart.AnnotationID = (i + 2);
    71.            answerP.Inlines.Add(rangestart);
    72.        }
    73. 
    74.        answerCell.Blocks.Add(answerP);
    75.        row.Cells.Add(answerCell);
    76.    }
    77. 
    78.    table.AddRow(row);
    79.}
    80. 
    81.section.Blocks.Add(table);

    Many Thanks,
    Chris

  2. Boby
    Admin
    Boby avatar
    595 posts

    Posted 03 Apr 2014 Link to this post

    Hi Chris,
    Adding paired read-only ranges in different table cells is not supported. What I can suggest is to use different approach - protect the whole document and then define what's editable. You can read more about document protection in this help article and  review this online demo.

    Don't hesitate to contact us if you have other questions.


    Regards,
    Boby
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Chris
    Chris avatar
    5 posts
    Member since:
    Jan 2014

    Posted 08 Apr 2014 in reply to Boby Link to this post

    Hi Boby,

    Thanks for the response. This does seem like a much nicer solution but I'm not sure if I'm adding the permission ranges correctly. I'm iterating through my table cells and using the Document.Selection.AddTableCellToSelection to select each cell and add an "Everyone" permission range to the rich text box using the current selection.Then setting the document protection to read only afterwards.

    This works fine except for when I tab between cells and attempt to enter text it only allows me 1 or 2 characters before not being able to enter anymore text. Additionally sometimes when I tab into a cell with text and entering text causes an InvalidOperationException saying "Selection contains uneditable ranges" coming from Telerik.Windows.Documents.dll.

    foreach (var row in this.Table.Rows)
    {
        foreach (var cell in row.Cells)
        {
            this.Doc.Selection.Clear();
            this.Doc.Selection.AddTableCellToSelection(cell);
            PermissionRangeInfo info = new PermissionRangeInfo();
            info.Type = PermissionType.Everyone;
            List<PermissionRangeInfo> infos = new List<PermissionRangeInfo>() { info };
            this.textBoxAnswer.InsertPermissionRange(infos);
        }
    }

    this.Doc.ProtectDocument(DocumentProtectionMode.ReadOnly, "password");


    Thanks again,
    Chris










  5. Boby
    Admin
    Boby avatar
    595 posts

    Posted 10 Apr 2014 Link to this post

    Hello Chris,
    It seems this is a bug in TabForwardCommand (the command that is bound to the the TAB key by default and performs navigation to the next table cell), which creates improper selection in the table cell. I will log the issue in our backlog, but with relatively low priority.

    Otherwise, the easiest way to insert such ranges would be with RadDocumentEditor. You do not need to select the table cells before calling InsertPermissionRange, positioning the caret in the empty cell will do the job:
    RadDocumentEditor editor = new RadDocumentEditor(document);
     
    IEnumerable<PermissionRangeInfo> everyonePermission = Enumerable.Repeat(new PermissionRangeInfo() { Type = PermissionType.Everyone }, 1);
     
    foreach (var row in table.Rows)
    {
        foreach (var cell in row.Cells)
        {
            editor.Document.CaretPosition.MoveToStartOfDocumentElement(cell);
     
            editor.InsertPermissionRange(everyonePermission);
        }
    }

    Is tabbing feature essential for your application? I am asking because navigating with mouse or arrows to the cells with permission ranges works as expected, and you can disable the TAB navigation by configuring TabForward command behaviors (NavigateInTable behavior should be excluded):
    <telerik:RadRichTextBox.InputBindings>
        <KeyBinding Gesture="Tab" Command="richTextBoxCommands:RichTextBoxCommands.TabForward" CommandParameter="InsertTabSymbol, ChangeParagraphListLevel, ChangeParagraphLeftIndent, AppendTableRow" />
    </telerik:RadRichTextBox.InputBindings>

    Let us know if this works for you.

    Regards,
    Boby
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Chris
    Chris avatar
    5 posts
    Member since:
    Jan 2014

    Posted 10 Apr 2014 in reply to Boby Link to this post

    Hello Boby,

    Thank you for the improved method for inserting the permission ranges. I'll disable the TAB navigation, it was just preferred over using the arrow keys if possible.

    Thanks again,
    Chris
  7. Boby
    Admin
    Boby avatar
    595 posts

    Posted 11 Apr 2014 Link to this post

    Hi Chris,
    I am glad that the workaround is sufficient for you. We have also added Telerik points to your account for the bug report. Don't hesitate to contact us if you have further questions.

    Regards,
    Boby
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready