ADOTable->DataSource->DBGridEh界面问题
ADOTable->DataSource->DBGridEh
这样的结构,不打算通过ADOQuery来处理。
界面上按序号排序Sort="序号"。
想实现通过单击一个按钮使得当前记录与下一记录的序号互换,即当前记录位置调整,下移一行
通过这样的代码,曾经貌似成功过,但现在行不通:
ADOTable1->DisableControls();
i3 = ADOTable1->RecNo;
i1 = ADOTable1->FieldByName("序号")->AsInteger;
ADOTable1->Next();
i4 = ADOTable1->RecNo;
i2 = ADOTable1->FieldByName("序号")->AsInteger;
ADOTable1->Edit();
ADOTable1->FieldByName("序号")->AsInteger = i1;
ADOTable1->Post();
ADOTable1->First();
ADOTable1->MoveBy(i3-1);
ADOTable1->Edit();
ADOTable1->FieldByName("序号")->AsInteger = i2;
ADOTable1->Post();
ADOTable1->Sort = "序号";
ADOTable1->MoveBy(i4-1);
DBGridhEh1->Refresh();
ADOTable1->EnableControls();
有时候序号交换了界面不更新,有时候序号都不会交换。
怎么办啊???要实现一个其他按钮按下后,当前记录下移(通过交换序号,按序号排序,刷新界面)。
[解决办法]
DBGridhEh1->Refresh();
ADOTable1->EnableControls();
先后顺序调整一下试试
[解决办法]
ADOTable1->Post();第一次修改后值发生变化了,后台又排序了,修改到另一条记录上去了
[解决办法]
void __fastcall TForm3::btn1Click(TObject *Sender)
{
int i1,i2;
int fixi=0;//一个不存在的值
String s1,s2,s3;
tbl1->DisableControls();
i1 = tbl1->FieldByName("id")->AsInteger;
s1 =tbl1->FieldByName("name")->AsString;
tbl1->Next();
i2 = tbl1->FieldByName("id")->AsInteger;
s2 =tbl1->FieldByName("name")->AsString;
tbl1->Edit();
tbl1->FieldByName("id")->AsInteger = fixi;
tbl1->Post();
tbl1->Locate("id",i1,TLocateOptions());
tbl1->Edit();
tbl1->FieldByName("id")->AsInteger = i2;
tbl1->Post();
//一个不存在的值
tbl1->Locate("id",fixi,TLocateOptions());
tbl1->Edit();
tbl1->FieldByName("id")->AsInteger = i1;
tbl1->Post();
tbl1->Sort = "id";
tbl1->EnableControls();
DBGrid1->Refresh();
}