Home Forums WinForms controls Xceed Grid for WinForms WinTextBox paste

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17063 |

    Hi,

    I have a cell with a WinTextBox. When I right click and select paste it works fine. My question is: how do I use this paste functionality from another means – like having a menu option called “paste” (so it will paste into the current cell). I don’t want to just set the cell to what’s in the clipboard because the user might be trying to paste text in between text that is already in the cell.

    vb.net please.

    Thanks in advance.

    Imported from legacy forums. Posted by troy@querytool.com (had 1452 views)

    User (Old forums)
    Member
    Post count: 23064

    You will need to retrieve the text from the WinTextBox editor that is used by the cell, and insert the string from the clipboard at the position of the caret.

    e.g.:

        private void pasteToolStripMenuItem_Click( object sender, EventArgs e )
        {
          WinTextBox textBox = gridControl1.CurrentCell.CellEditorControl as WinTextBox;
          if( textBox != null )
          {
            int selectionStartIndex = textBox.TextBoxArea.SelectionStart;
            string text = textBox.TextBoxArea.Text.Remove( selectionStartIndex, textBox.TextBoxArea.SelectionLength );
            string clipboard = Clipboard.GetText();
            textBox.TextBoxArea.Text = text.Insert( selectionStartIndex, clipboard );
          }
        }

    Note however that you may need to add some validation so it will not throw any exception in all the scenarios you want it to support.

    Imported from legacy forums. Posted by André (had 1686 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.