locked
Set Cursor Position in ComboBox RRS feed

  • Question

  • Hello, I won't get into the details as to why... But does anyone know how to set the cursor position?
    Wednesday, October 15, 2008 8:04 PM

Answers

  • The overload of ComboBox.Select that takes two integer values is what you're looking for.


    David Morton - http://blog.davemorton.net/
    • Marked as answer by CommanderKeen Wednesday, October 15, 2008 8:12 PM
    Wednesday, October 15, 2008 8:09 PM

All replies

  • The overload of ComboBox.Select that takes two integer values is what you're looking for.


    David Morton - http://blog.davemorton.net/
    • Marked as answer by CommanderKeen Wednesday, October 15, 2008 8:12 PM
    Wednesday, October 15, 2008 8:09 PM
  • CommanderKeen said:

    Hello, I won't get into the details as to why... But does anyone know how to set the cursor position?



    What do you mean by "cursor position"?  There are a number of ComboBox properties that start with the word "Select..." 

    If you need to know exactly where the cursor is at any given moment, you might need to create a custom control by inheriting ComboBox.  Add a property that reports your "cursor position".  Be sure to include methods that track the user's keypresses so that you can track where the cursor is in the Current Selection and/or Current Item.

    Rudedog   =8^D
    Mark the best replies as answers. "Fooling computers since 1971."
    Wednesday, October 15, 2008 8:12 PM
  • Rudedog2 said:

    If you need to know exactly where the cursor is at any given moment, you might need to create a custom control by inheriting ComboBox.  Add a property that reports your "cursor position".  Be sure to include methods that track the user's keypresses so that you can track where the cursor is in the Current Selection and/or Current Item.

    Rudedog   =8^D
    Mark the best replies as answers. "Fooling computers since 1971."



    You can get the current selection by checking the SelectionStart and SelectionLength properties of the ComboBox.
    David Morton - http://blog.davemorton.net/
    Wednesday, October 15, 2008 8:19 PM
  •  
    Rudedog2 said:

    CommanderKeen said:

    Hello, I won't get into the details as to why... But does anyone know how to set the cursor position?



    What do you mean by "cursor position"?  There are a number of ComboBox properties that start with the word "Select..." 

    If you need to know exactly where the cursor is at any given moment, you might need to create a custom control by inheriting ComboBox.  Add a property that reports your "cursor position".  Be sure to include methods that track the user's keypresses so that you can track where the cursor is in the Current Selection and/or Current Item.

    Rudedog   =8^D
    Mark the best replies as answers. "Fooling computers since 1971."



    By Cursor position I mean relative to the text within a comboBox.  Example: When you click the mouse on a string "example" at a position between 'x' and 'a' the cursor is then set to this position.

     I don't need to get the cursor position only set.  David's suggestion of 'ComboBox.Select' worked. Example: to set the cursor position at index 'i' I would merely write:

    comboBox1.Select(i, i);

    Wednesday, October 15, 2008 8:19 PM
  • I figured you meant that, that is why I was so vague.  Wasn't sure.  As I said, there are a number of properties that begin with "Select..." that are pretty flexible.  Happy Coding.

    Rudedog  =8^D
    Mark the best replies as answers. "Fooling computers since 1971."
    Wednesday, October 15, 2008 10:42 PM
  • Thanks for the response.
    Thursday, October 16, 2008 1:24 AM