Dbgrid控件多重选择的怪问题。BookMarkList,BookMark,使用书签,用的ADOQuery控件。100分送上,急阿!!!请高手帮忙! ( 积分: 100 )<br />procedure TForm_ContinuPrnt.BitB_PrintClick(Sender: TObject);
Var
i,x:Integer;
BookMarkList:TBookMarkList ;
BookMark:TBookMark;
getClientCode,getPre,getThis,getFact,getPrice,getMoney,getName:String;
begin
With MyDataModule do
Begin
AQ_DataKeep.Close;
AQ_DataKeep.SQL.Clear;
AQ_DataKeep.SQL.Add('Select a.ClientCode,a.Years,a.Months,a.PreData,a.Thisdata,a.FactData,a.Price,a.AmountMoney,a.PrintMask,a.BankDeduct,b.ClientNo,b.ClientCode,b.AreaNo,b.UseName');
AQ_DataKeep.SQL.Add('From EdataKeep a,EClientInfo b');
AQ_DataKeep.SQL.Add('Where (a.ClientCode=b.ClientCode) And (b.AreaNo=AA) And (a.Years=YY) And (a.Months=MM)');
AQ_DataKeep.SQL.Add('Order By b.ClientNo');
AQ_DataKeep.Parameters.ParamByName('pAA').Value:=getAreaNo;
AQ_DataKeep.Parameters.ParamByName('pYY').Value:= getYear;
AQ_DataKeep.Parameters.ParamByName('pMM').Value:= getmonth;
AQ_DataKeep.Prepared;
AQ_DataKeep.Open;
BookMark:=AQ_DataKeep.GetBookmark ; //....获得书签.......
BookmarkList:=Dbgrid1.SelectedRows; //。。。该行也有问题
x:=BookmarkList.Count; //。。。该行有问题,结果总是 0
Try
For i:=0 to BookmarkList.Count-1 do //因为BookmarkList.Count 总是0 ,程序不能对网格中选择的多行数据操作
begin
AQ_DataKeep.GotoBookmark(Pointer(Dbgrid1.SelectedRows));
getClientCode:=AQ_DataKeep.FieldByname('ClientCode').AsString;
getPre:=AQ_DataKeep.FieldByname('PreData').AsString;
getThis:=AQ_DataKeep.FieldByname('ThisData').AsString;
getFact:=AQ_DataKeep.FieldByname('FactData').AsString;
getPrice:=AQ_DataKeep.FieldByname('Price').AsString;
getMoney:=AQ_DataKeep.FieldByname('AmountMoney').AsString;
getName:=AQ_DataKeep.FieldByname('useName').AsString;
end;
except
AQ_DataKeep.GotoBookmark(Bookmark) ;
AQ_DataKeep.FreeBookmark(Bookmark) ;
end;
end;
end;
DBgrid控件可以设置了Option中的dgMultiSelect 为true后,就可以在界面上按住Ctrl(contral)键,对网格的数据进行多个选择。对数据多个选择后,可以只对选择的多行数据操作。但是,我用的数据控件是ADOQuery(就是程序中的AQ_DataKeep),因为BookmarkList.Count 总是0 ,程序不能对网格中选择的多行数据操作,请问这是为什么?
我用Ttable控件就一切都正常(数据库是paradox)!用ADOQuery控件(数据库是SQL 2000)就不行,请高手回答!
procedure TForm_ContinuPrnt.BitB_PrintClick(Sender: TObject);
Var
i,x:Integer;
BookMarkList:TBookMarkList ;
BookMark:TBookMark;
getClientCode,getPre,getThis,getFact,getPrice,getMoney,getName:String;
begin
With MyDataModule do
Begin
AQ_DataKeep.Close;
AQ_DataKeep.SQL.Clear;
AQ_DataKeep.SQL.Add('Select a.ClientCode,a.Years,a.Months,a.PreData,a.Thisdata,a.FactData,a.Price,a.AmountMoney,a.PrintMask,a.BankDeduct,b.ClientNo,b.ClientCode,b.AreaNo,b.UseName');
AQ_DataKeep.SQL.Add('From EdataKeep a,EClientInfo b');
AQ_DataKeep.SQL.Add('Where (a.ClientCode=b.ClientCode) And (b.AreaNo=AA) And (a.Years=YY) And (a.Months=MM)');
AQ_DataKeep.SQL.Add('Order By b.ClientNo');
AQ_DataKeep.Parameters.ParamByName('pAA').Value:=getAreaNo;
AQ_DataKeep.Parameters.ParamByName('pYY').Value:= getYear;
AQ_DataKeep.Parameters.ParamByName('pMM').Value:= getmonth;
AQ_DataKeep.Prepared;
AQ_DataKeep.Open;
BookMark:=AQ_DataKeep.GetBookmark ; //....获得书签.......
BookmarkList:=Dbgrid1.SelectedRows; //。。。该行也有问题
x:=BookmarkList.Count; //。。。该行有问题,结果总是 0
Try
For i:=0 to BookmarkList.Count-1 do //因为BookmarkList.Count 总是0 ,程序不能对网格中选择的多行数据操作
begin
AQ_DataKeep.GotoBookmark(Pointer(Dbgrid1.SelectedRows));
getClientCode:=AQ_DataKeep.FieldByname('ClientCode').AsString;
getPre:=AQ_DataKeep.FieldByname('PreData').AsString;
getThis:=AQ_DataKeep.FieldByname('ThisData').AsString;
getFact:=AQ_DataKeep.FieldByname('FactData').AsString;
getPrice:=AQ_DataKeep.FieldByname('Price').AsString;
getMoney:=AQ_DataKeep.FieldByname('AmountMoney').AsString;
getName:=AQ_DataKeep.FieldByname('useName').AsString;
end;
except
AQ_DataKeep.GotoBookmark(Bookmark) ;
AQ_DataKeep.FreeBookmark(Bookmark) ;
end;
end;
end;
DBgrid控件可以设置了Option中的dgMultiSelect 为true后,就可以在界面上按住Ctrl(contral)键,对网格的数据进行多个选择。对数据多个选择后,可以只对选择的多行数据操作。但是,我用的数据控件是ADOQuery(就是程序中的AQ_DataKeep),因为BookmarkList.Count 总是0 ,程序不能对网格中选择的多行数据操作,请问这是为什么?
我用Ttable控件就一切都正常(数据库是paradox)!用ADOQuery控件(数据库是SQL 2000)就不行,请高手回答!
对DBGrid 进行多行选择时,好像已经实现GetBookmark 了。你可以将如下该行:For i:=0 to BookmarkList.Count-1 do //因为BookmarkList.Count 总是0 ,程序不能对网格中选择的多行数据操作
修改为:for i := 0 to Dbgrid1.SelectedRows.Count - 1 do
begin
Dbgrid1.DataSource.DataSet.GotoBookmark(pointer(Dbgrid1.SelectedRows.Items));
我已经自己搞定了。问题不在这里!(zgj_gd)
问题在于数据集控件AQ_DataKeep,应该在其他地方打开,因为每次重新打开,界面上的
Dbgrid1.SelectedRows,与BookmarkList,bookMark 都是空了。
我要发分了,需要分的朋友近来拿分。