2010. január 15., péntek

How to insert text into a TComboBox at the last cursor position


The goal is to insert a string into the text in a TComboBox at the last cursor position. An assignment like edInput.SelText := newText; works fine with a TEdit when AutoSelect = false, but not with combobox. SelStart always returns 0 after exiting. So no matter where the user had the cursor, the text is always inserted at the front. Is there a quick workaround for this?


Assign the Combobox.selstart value to a variable on the KeyUp event of the combobox and call the variable when you need the position. You can take the hint as a variable or declare your own variable.

procedure TForm1.ComboBox1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  ComboBox1.hint := inttostr(Combobox1.selstart);

Nincsenek megjegyzések:

Megjegyzés küldése