1. 程式人生 > >Dbgrid控件多重選擇的怪問題。BookMarkList,BookMark,使用書簽,用的ADOQuery控件。100分送上,急阿!!!請高手幫忙!

Dbgrid控件多重選擇的怪問題。BookMarkList,BookMark,使用書簽,用的ADOQuery控件。100分送上,急阿!!!請高手幫忙!

ask .data int data- out bae inf tar 重新

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 都是空了。

我要發分了,需要分的朋友近來拿分。


Dbgrid控件多重選擇的怪問題。BookMarkList,BookMark,使用書簽,用的ADOQuery控件。100分送上,急阿!!!請高手幫忙!