I noticed that the default lookup-columns for the NextDbGrid only respond to the first character typed.
As a result the user can't select the desired value by typing the first few characters.
Example :
In list we might have:
- Booz 30Cl
- Booz 50Cl
- Cheerz 30Cl
- Cheerz 50Cl
Typing 'Cheerz 5' should select 'Cheerz 50Cl', but instead it only selects the first entry with that letter ( 'Cheerz 30Cl' )
I tried using the AutoComplete-control according to the example provided on this website, but it doesn't appear to work at all.
It's also a lot of extra code (for filling the autocomplete list) that probably can be avoided as well.
AutoComplete and (Lookup)Combo possible?
Started by rond, Feb 14 2011 12:44 PM
2 replies to this topic
#1
Posted 14 February 2011 - 12:44 PM
#2
Posted 15 February 2011 - 02:03 PM
I've managed to get it working by setting 'AutoComplete' to true.
However I noticed that the user always has to press 'backspace' in order to activate this feature.
However I noticed that the user always has to press 'backspace' in order to activate this feature.
#3
Posted 16 February 2011 - 03:58 PM
It's still not working like I need it to.
I did however manage to get a partial fix that gets rid of the backspace requirement.
As I already was using the keydown-event to start the editor whenever the user pressed the spacebar I used this code :
procedure TfrShiftProducts.grdShiftProductsKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
// if 'spacebar' is pressed ...
if(Key = VK_SPACE) then
begin
// start the editor for the selected cell :
grdShiftProducts.EditCell(grdShiftProducts.SelectedColumn, grdShiftProducts.SelectedRow);
// this routine is needed to start autocomplete
FixAutoComplete;
// set Key to 0 as we don't want it anymore
Key := 0
end;
end;
procedure TfrShiftProducts.FixAutoComplete;
var
iHandle : HWND;
iLast : integer;
begin
// get the handle for the active editor and the length of the text
if grdShiftProducts.Columns[grdShiftProducts.SelectedColumn].InplaceEdit = Nil then
begin
iHandle := grdShiftProducts.Columns[grdShiftProducts.SelectedColumn].Editor.Handle;
iLast := Length(grdShiftProducts.Columns[grdShiftProducts.SelectedColumn].Editor.Text)
end else
begin
iHandle := grdShiftProducts.Columns[grdShiftProducts.SelectedColumn].InplaceEdit.Handle;
iLast := Length(grdShiftProducts.Columns[grdShiftProducts.SelectedColumn].InplaceEdit.Tex
t)
end;
// this appears to 'fix' it :
SendMessage(iHandle, EM_SETSEL, 0, MakeLParam(iLast - 1, iLast - 1));
end;
I did however manage to get a partial fix that gets rid of the backspace requirement.
As I already was using the keydown-event to start the editor whenever the user pressed the spacebar I used this code :
CODE
procedure TfrShiftProducts.grdShiftProductsKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
// if 'spacebar' is pressed ...
if(Key = VK_SPACE) then
begin
// start the editor for the selected cell :
grdShiftProducts.EditCell(grdShiftProducts.SelectedColumn, grdShiftProducts.SelectedRow);
// this routine is needed to start autocomplete
FixAutoComplete;
// set Key to 0 as we don't want it anymore
Key := 0
end;
end;
procedure TfrShiftProducts.FixAutoComplete;
var
iHandle : HWND;
iLast : integer;
begin
// get the handle for the active editor and the length of the text
if grdShiftProducts.Columns[grdShiftProducts.SelectedColumn].InplaceEdit = Nil then
begin
iHandle := grdShiftProducts.Columns[grdShiftProducts.SelectedColumn].Editor.Handle;
iLast := Length(grdShiftProducts.Columns[grdShiftProducts.SelectedColumn].Editor.Text)
end else
begin
iHandle := grdShiftProducts.Columns[grdShiftProducts.SelectedColumn].InplaceEdit.Handle;
iLast := Length(grdShiftProducts.Columns[grdShiftProducts.SelectedColumn].InplaceEdit.Tex
t)
end;
// this appears to 'fix' it :
SendMessage(iHandle, EM_SETSEL, 0, MakeLParam(iLast - 1, iLast - 1));
end;
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users










