Unexpected behaviour of TTable and TDBGrid in Delphi XE2

前端 未结 1 1052
长情又很酷
长情又很酷 2021-01-28 10:47

I have a textbox and a grid on a form.

Functionality: When I enter an Emp ID (say 1, 2, 3 etc) in textbox, corresponding to that Emp ID, Emp Name shoul

1条回答
  •  情歌与酒
    2021-01-28 11:23

    To define the order of records you have to use indexes/primary key. Add it like in code below.

    Table1.FieldDefs.Add('EmpId', ftAutoInc, 0, True);
    Table1.FieldDefs.Add('EmpName', ftString, 40);
    Table1.IndexDefs.Add('idxEmpId','EmpId',[ixPrimary]);
    Table1.CreateTable;
    Table1.Open;
    

    You can hide EmpId from viewing in grid by defining DBGrid.Columns property, where show only necessary columns.

    0 讨论(0)
提交回复
热议问题