in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Move Cursor Position in flexgrid editor

Last post 05-15-2008 7:53 AM by C1_DaveT. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 05-14-2008 12:39 PM

    Move Cursor Position in flexgrid editor

    I have a flexgrid setup to where the user inputs a string until they have the keypress of { when they type in { a dialog box appears having them select a 7 character string.  This 7 character string is then inserted into the string at the position of the textbox SelectionStart and saved back to the editor for further editing.  Once this is done however the position of the cursor in the edit box goes back to the beginning of the string.  I want the cursor to now appear after the 7th character of the inserted value.  Example:

    I have the string:

    The quick brown jumps over the lazy dog

    The user edits the cell and types in the following:

    The quick brown { jumps over the lazy dog

    The { opens a dialog box for the user to choose an animal.  The user chooses Fox

    The quick brown fox jumps over the lazy dog

    but now the edit cursor is in front of the T in The.  I want the cursor to be after x in Fox.  How do I move that cursor in the editor.  Here is a sample of code I have.

    Private Sub fg_KeyPressEdit(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.KeyPressEditEventArgs) Handles fg.KeyPressEdit

    Dim tb As TextBox

    If Not IsNothing(fg.Editor) Then
      Try
         tb = fg.Editor
      Catch ex As Exception
         Exit Sub
      End Try

      If Len(tb.SelectedText) > 1 Then
         fgSelectedTxtIndex = tb.SelectionStart
      End If
    End If

    If e.KeyChar = "{" Then
      Dim frm As New frmChooser
      Dim strModifed As String
     
      frm.ShowDialog()

      strModifed = fg.Editor.Text

      strModifed = strModifed.Insert(tb.SelectionStart, strChoosenString)

      fg.Editor.Text = strModifed

      'Removes Initial Key Stroke
       e.Handled = True
    End If

    'TODO: Insert Code to Move Cursor in Editor

    end sub

    Any Help would be greatly appreciated.

    Thanks,

  • 05-15-2008 7:53 AM In reply to

    Re: Move Cursor Position in flexgrid editor

    This can be done by setting SelectionStart property of text box which represents FlexGrid Editor. Here you are using text box ‘tb’ which can be used for this purpose.

     

    Such as -

    ---------------------Start Code ---------------------

    Private Sub fg_KeyPressEdit(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.KeyPressEditEventArgs) Handles fg.KeyPressEdit

    Dim tb As TextBox

     Dim initialPos As Integer

    If Not IsNothing(fg.Editor) Then
      Try
         tb = fg.Editor
      Catch ex As Exception
         Exit Sub
      End Try

      If Len(tb.SelectedText) > 1 Then
         fgSelectedTxtIndex = tb.SelectionStart
      End If
    End If

    If e.KeyChar = "{" Then

      initialPos = tb.SelectionStart


      Dim frm As New frmChooser
      Dim strModifed As String
     
      frm.ShowDialog()

      strModifed = fg.Editor.Text

      strModifed = strModifed.Insert(tb.SelectionStart, strChoosenString)

    fg.Editor.Text = strModifed

      tb.SelectionStart = initialPos+ strChoosenString.length()

      'Removes Initial Key Stroke
       e.Handled = True
    End If

    end sub

     -----------------------End Code -----------------------

     

    I hope this resolves the issue.

     

    -Dave.

     

     

    <Scott_Cli> wrote in message news:204861@10.0.1.98...

    I have a flexgrid setup to where the user inputs a string until they have the keypress of { when they type in { a dialog box appears having them select a 7 character string.  This 7 character string is then inserted into the string at the position of the textbox SelectionStart and saved back to the editor for further editing.  Once this is done however the position of the cursor in the edit box goes back to the beginning of the string.  I want the cursor to now appear after the 7th character of the inserted value.  Example:

    I have the string:

    The quick brown jumps over the lazy dog

    The user edits the cell and types in the following:

    The quick brown { jumps over the lazy dog

    The { opens a dialog box for the user to choose an animal.  The user chooses Fox

    The quick brown fox jumps over the lazy dog

    but now the edit cursor is in front of the T in The.  I want the cursor to be after x in Fox.  How do I move that cursor in the editor.  Here is a sample of code I have.

    Private Sub fg_KeyPressEdit(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.KeyPressEditEventArgs) Handles fg.KeyPressEdit

    Dim tb As TextBox

    If Not IsNothing(fg.Editor) Then
      Try
         tb = fg.Editor
      Catch ex As Exception
         Exit Sub
      End Try

      If Len(tb.SelectedText) > 1 Then
         fgSelectedTxtIndex = tb.SelectionStart
      End If
    End If

    If e.KeyChar = "{" Then
      Dim frm As New frmChooser
      Dim strModifed As String
     
      frm.ShowDialog()

      strModifed = fg.Editor.Text

      strModifed = strModifed.Insert(tb.SelectionStart, strChoosenString)

      fg.Editor.Text = strModifed

      'Removes Initial Key Stroke
       e.Handled = True
    End If

    'TODO: Insert Code to Move Cursor in Editor

    end sub

    Any Help would be greatly appreciated.

    Thanks,



    http://helpcentral.componentone.com/cs/forums/p/75247/204861.aspx#204861

Page 1 of 1 (2 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.