如何在DBGRID搜索符合条件记录时候,DBGRID没有跳动的感觉? 非常难,斑竹帮忙~~~

sgq_hit 2003-10-19 11:34:26
用以下代码dbgrid界面上下跳动,感觉非常不好。
Psg_DBGrid数据源是query,不需要update,insert,delete。
有没有好办法?

TDataSet *pDS = Psg_DBGrid->DataSource->DataSet;
pDS->First();
while (!pDS->Eof)
{
AnsiString sCurPsrHostNum;
int index;
sCurPsrHostNum = pDS->FindField("psr_hostnbr")->AsString;
for (int i = 0; i < pSelPsrHostnbr->Count; i++)
{
sCurPsrHostNum = pDS->FindField("psr_hostnbr")->AsString;
if (pSelPsrHostnbr->Strings[i] == sCurPsrHostNum)
{
Psg_DBGrid->SelectedRows->CurrentRowSelected = true;
break;
}
}
pDS->Next();
}
...全文
38 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
seamansoft 2003-10-20
  • 打赏
  • 举报
回复
实际是搜索ADOQuery1,而不是DBGrid:
TLocateOptions loOptions;
loOptions<<loCaseInsensitive;
if(!ADOQuery1->Locate("FieldName",FieldValue,loOptions))
{
MessageBox(Handle,"...","...",MB_ICONINFORMATION);
}
关于TLocateOptions,请查阅帮助。
cnphw 2003-10-19
  • 打赏
  • 举报
回复
要不简单点,自己处理

TDataSet *pDS = Psg_DBGrid->DataSource->DataSet;
Psg_DBGrid->DataSource=NULL;
pDS->First();
while (!pDS->Eof)
{
AnsiString sCurPsrHostNum;
int index;
sCurPsrHostNum = pDS->FindField("psr_hostnbr")->AsString;
for (int i = 0; i < pSelPsrHostnbr->Count; i++)
{
sCurPsrHostNum = pDS->FindField("psr_hostnbr")->AsString;
if (pSelPsrHostnbr->Strings[i] == sCurPsrHostNum)
{
Psg_DBGrid->SelectedRows->CurrentRowSelected = true;
break;
}
}
pDS->Next();
}
Psg_DBGrid->DataSource=*pDS ;

cnphw 2003-10-19
  • 打赏
  • 举报
回复
好久没有用了,资料上都有,好像把TDataSet显示功能关掉,查到后再打开
netsys2 2003-10-19
  • 打赏
  • 举报
回复
用这个:

TDataSet::DisableControls


Disables data display in data-aware controls associated with the dataset.

void __fastcall DisableControls(void);

Description

Call DisableControls prior to iterating through a large number of records in the dataset to prevent data-aware controls from updating every time the active record changes. Disabling controls prevents flicker and speeds performance because data does not need to be written to the display.

If controls are not already disabled, DisableControls records the current state of the dataset, broadcasts the state change to all associated data-aware controls and detail datasets, and increments the dataset抯 disabled count variable. Otherwise, DisableControls just increments the disabled count variable.

The disabled count is used internally by other methods and objects to determine whether to display data in data-aware controls. When the disable count variable is greater than zero, data is not displayed.

If the dataset is the master of a master/detail relationship, calling DisableControls also disables the master/detail relationship. Setting BlockReadSize instead of calling DisableControls updates the detail datasets as you scroll through the dataset, but does not update data-aware controls.

Note: DisableControls can safely be called when controls are already disabled. In complex applications there may be separate operations that are sometimes nested, both of which need to disable controls.

examples:

CustTable->DisableControls();

try
{
CustTable->First();
while (!CustTable->Eof)
{
// Process each record here
CustTable->Next();
}
__finally
{
CustTable->EnableControls();
}
}
耙子 2003-10-19
  • 打赏
  • 举报
回复
这类的查找为什么不用现成的 Locate,不用你自己写这些代码。

其次,
Psg_DBGrid.DataSource.DataSet.DisableControls;

//你的查找代码

// 查找结束
Psg_DBGrid.DataSource.DataSet.EnableControls;

这个可以在你查找的过程中,让数据集和DBGrid断开,速度会大大的提高。

1,178

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 数据库及相关技术
社区管理员
  • 数据库及相关技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧