求救啊,DBGrid闪烁的问题!
目的:鼠标在DBGrid上移动,不点击鼠标,把鼠标所在的地方的那条记录的某个值(没有在表格中显示出来,但DataSet中有)用Hint的方式显示出来。
Unit1.h
private: // User declarations int OLDX,OLDY; THintWindow *fmHint;
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){ Application->CreateForm(HintWindowClass,&fmHint); Form1->DoubleBuffered=true; DBG->DoubleBuffered=true; DBGrid1->DoubleBuffered=true;}//---------------------------------------void __fastcall TForm1::DBGrid1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y){ AnsiString Str; TGridCoord p=DBGrid1->MouseCoord(X,Y); Str="X="+IntToStr(p.X)+" Y="+IntToStr(p.Y); if(p.X>0&&p.Y>0) { if(OLDX!=p.X||OLDY!=p.Y) { class TMyGrid:public TCustomDBGrid { public: __property DataLink; }; TMyGrid *MyGrid=(TMyGrid*)DBGrid1; MyGrid->DataSource->DataSet->DisableControls(); int i=MyGrid->DataLink->ActiveRecord; TBookmark BM; BM=DBG->DataSource->DataSet->GetBookmark(); MyGrid->DataSource->DataSet->MoveBy(OLDY-i-1); Str+="\n"+MyGrid->DataSource->DataSet->FieldByName("OrderID")->AsString; if(MyGrid->DataSource->DataSet->FieldByName("Brand")->AsString!="") Str+="\n"+MyGrid->DataSource->DataSet->FieldByName("Brand")->AsString; if(MyGrid->DataSource->DataSet->FieldByName("Note")->AsString!="") Str+="\n"+MyGrid->DataSource->DataSet->FieldByName("Note")->AsString; MyGrid->DataLink->ActiveRecord=i; MyGrid->DataSource->DataSet->GotoBookmark(BM); MyGrid->DataSource->DataSet->FreeBookmark(BM); MyGrid->DataSource->DataSet->EnableControls(); TRect R = fmHint->CalcHintRect(1000,Str,NULL); TPoint P = Mouse->CursorPos; OffsetRect(R,P.x,P.y); fmHint->ActivateHint(R,Str); } OLDX=p.X; OLDY=p.Y; } else { OLDX=p.X; OLDY=p.Y; fmHint->ReleaseHandle(); }}//---------------------------------------
class TMyGrid:public TCustomDBGrid //放到头文件去{ public: __property DataLink;};TMyGrid *MyGrid=(TMyGrid*)DBGrid1; //在头文件中,把 MyGrid 作为 TForm1 的一个类成员,然后把这行代码放在 TForm1 的 Create 事件中//MouseMove 事件触发的频率很高(鼠标移动时),你每次触发这个事件,都要定义一个类,并且生成它的一个对象(并且这个对象比较复杂),每次事件结束时还要析构,这样效率会非常低下,还不如把这个类生成的对象作为一个全局变量比较快
[解决办法]
好贴,学习下
[解决办法]
DBGRID闪烁是刷新的问题吧。
[解决办法]
帮顶不要分