Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move to a Column

Status
Not open for further replies.

wrov

Programmer
Nov 1, 2002
43
PY
Hi everybody

Do you know how to go to a column in a DBGrid ?

If the cursor is in the column #1 and the user press the ENTER key: how to do for move the cursor to the column # 5?

Thanks in advance.

Walter.
 
Try this example out:

You should program the event "onKeyDown" of your DbGrid:

procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=vk_Return then
begin
with DbGrid1 do
begin
if SelectedField.FieldNo=1 then
SelectedField:=Fields[4];
end;
end;
end;

Hope this helps...
 
Do you wish to jump to field # 5 or to move one field to the right or left at a time?
Try this - press the tab key to move to right or shift + tab key to move to the left.
yomyom
 
Alternatively,
drop a list box with values equal to the number of fields
then use the list box to set how many columns to jump at a time e.g
listbox1.selected will return a value.

dbgrid1.selectedField.FieldNo := listbox1.selected;
yomyom.
 
Or ;-)

On the OnKeyDown event of the DBGrid

if Key=VK_RETURN then begin
DBGrid1.SelectedField := Table1.FieldByName('FieldName');
end;
 
To wyjkmsc and BTecho

Thank you very much. You had answered the question.

Walter.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top