我从cxGrid上多选了一些纪录,用于打印,程序实现如下:
在a表单上选中纪录,按打印
if PrintBtn.Caption='打 印' then begin
if PrintCheckBox.Checked then
MainForm.CopyData(cxGrid1DBTableView1,PrintCheckBox.Checked,'CAR_MSG.CARID','牌照号码');
MainForm.PrintReport(MainForm.PrintDBGrid,CarManagerDM.PrintAdoQry,'车辆户籍化表.RTM');
这里我将a表单上的一个cxGrid作为参数传递给主表单。然后在主表单上:
Printlistbox.Items.Clear;
//PrintSumEdit.Text :=IntToStr(MainTaskGridDBTableView1.DataController.GetSelectedCount);//Total all Selected items into Disp
if isSelected then begin
mystr:=' OR '+KeyStr1+'= ''';
myStr2:='';
selcou:=MainTaskGridDBTableView1.DataController.GetSelectedCount;
MainTaskGridDBTableView1.DataController.datasource.dataset.DisableControls; {Disable controls to improve performance}
for i:=0 to selcou-1 do begin
with MainTaskGridDBTableView1.DataController do begin
myRowIndex:=GetSelectedRowIndex(i); //这里得到的是纪录在那一行上
myItemIndex:=GridView.IndexOfItem(GetItemByFieldName(KeyStr2));//这里得到纪录在那一列上
PrintListbox.items.add(GetValue(myRowIndex,myItemIndex));
if i=0 then
myStr1:=' '+KeyStr1+'= '''+PrintListBox.Items.Strings[i]+''''
else
myStr2:=myStr2+myStr+PrintListBox.Items.Strings[i]+'''';
end;
end;
if selcou>0 then
mystr:=' AND ( '+mystr1+mystr2+') '
else
myStr:=' AND '+KeyStr1+'='''+CarManagerDM.PrintAdoQry.FieldValues[KeyStr2]+'''';
with CarManagerDM.PrintADOQry do begin
Close;
SQl.Clear;
SQl.Add(PrintStartStr+myStr);
Open;
end;
MainTaskGridDBTableView1.DataController.datasource.dataset.EnableControls; { Re-enable controls }
end;
end;现在的问题是:若a表单上没有经过任何的排序和column的移动,打印的纪录是对的,若有排序,则打印的纪录就不对了。
我看了一下,在主表单下得到的纪录所在列是该纪录没有排序前的值。
这个问题该如何解决,谢谢??????
在a表单上选中纪录,按打印
if PrintBtn.Caption='打 印' then begin
if PrintCheckBox.Checked then
MainForm.CopyData(cxGrid1DBTableView1,PrintCheckBox.Checked,'CAR_MSG.CARID','牌照号码');
MainForm.PrintReport(MainForm.PrintDBGrid,CarManagerDM.PrintAdoQry,'车辆户籍化表.RTM');
这里我将a表单上的一个cxGrid作为参数传递给主表单。然后在主表单上:
Printlistbox.Items.Clear;
//PrintSumEdit.Text :=IntToStr(MainTaskGridDBTableView1.DataController.GetSelectedCount);//Total all Selected items into Disp
if isSelected then begin
mystr:=' OR '+KeyStr1+'= ''';
myStr2:='';
selcou:=MainTaskGridDBTableView1.DataController.GetSelectedCount;
MainTaskGridDBTableView1.DataController.datasource.dataset.DisableControls; {Disable controls to improve performance}
for i:=0 to selcou-1 do begin
with MainTaskGridDBTableView1.DataController do begin
myRowIndex:=GetSelectedRowIndex(i); //这里得到的是纪录在那一行上
myItemIndex:=GridView.IndexOfItem(GetItemByFieldName(KeyStr2));//这里得到纪录在那一列上
PrintListbox.items.add(GetValue(myRowIndex,myItemIndex));
if i=0 then
myStr1:=' '+KeyStr1+'= '''+PrintListBox.Items.Strings[i]+''''
else
myStr2:=myStr2+myStr+PrintListBox.Items.Strings[i]+'''';
end;
end;
if selcou>0 then
mystr:=' AND ( '+mystr1+mystr2+') '
else
myStr:=' AND '+KeyStr1+'='''+CarManagerDM.PrintAdoQry.FieldValues[KeyStr2]+'''';
with CarManagerDM.PrintADOQry do begin
Close;
SQl.Clear;
SQl.Add(PrintStartStr+myStr);
Open;
end;
MainTaskGridDBTableView1.DataController.datasource.dataset.EnableControls; { Re-enable controls }
end;
end;现在的问题是:若a表单上没有经过任何的排序和column的移动,打印的纪录是对的,若有排序,则打印的纪录就不对了。
我看了一下,在主表单下得到的纪录所在列是该纪录没有排序前的值。
这个问题该如何解决,谢谢??????
解决方案 »
- 访问ssl的webservice
- 对richedit控件的selAttribute属性的疑问
- 急 求 大富翁论坛chm
- ●●●●为了自己方便,也为大家方便,建立了一个DELPHI程序员QQ群:8194759●●●●
- Table控件的一个难题?
- 再线等2000系统下怎样让红色警戒联机谢谢!
- lobyte hibyte 是干什么用的啊.在D7里怎么没有啊.
- 帮忙推荐一些关于windows消息机制的资料<打赏100文啦>
- ODBC的SQLSetPos、SQLSetCursorName等函数的问题
- spreadsheet中文折行的问题,中文折行后为乱码
- 想转行JAVA的,就进来看看吧,觉得DELPHI工资低了的就进来看看吧。
- 如何判断一个文件是否打开?还望指教,谢谢!
cxGrdDataTV.DragMode := dmAutomatic
cxGrdDataTV.OptionsSelection.MultiSelect :=True
B.写事件DragOver
procedure TForm1.cxGrdDataTVDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure SwapInt(var A, B: integer);
var
tmp: Integer;
begin
tmp := a;
a := b;
b := tmp;
end;
var
AHitTest: TcxCustomGridHitTest;
i, IndexStart, IndexEnd: integer;
begin
if cxGrdDataTV.DragMode <> dmAutomatic then
Exit;
if cxGrdDataTV.OptionsSelection.MultiSelect = False then
Exit;
cxGrdDataTV.BeginUpdate;
AHitTest := cxGrdDataTV.ViewInfo.GetHitTest(X, Y);
if AHitTest is TcxGridRecordHitTest then
begin
IndexStart := cxGrdDataTV.Controller.FocusedRecord.Index;
IndexEnd := TcxGridRecordHitTest(AHitTest).GridRecord.Index;
cxGrdDataTV.Controller.ClearSelection;
if IndexEnd < IndexStart then
SwapInt(IndexStart, IndexEnd);
for i := IndexStart to IndexEnd do
cxGrdDataTV.ViewData.Records[i].Selected := True;
end;
cxGrdDataTV.EndUpdate;
end;C.获取选中的值
procedure TForm1.Button3Click(Sender: TObject);
var
i,myItemIndex : integer;
sID : string;
begin
//指定要获取的值
myItemIndex:=cxGrdDataTV.DataController.GridView.IndexOfItem(cxGrdDataTV.DataController.GetItemByFieldName('shCode')); for i := 0 to cxGrdDataTV.DataController.Controller.SelectedRecordCount - 1 do
begin
sID := cxGrdDataTV.DataController.Controller.SelectedRecords[i].Values[myItemIndex];
Memo1.Lines.Add(sID);
end;
end;//*********谢谢,我们遇到同样的问题,解决你的问题,你还要改一下这段代码;谢谢,没有分,让我有一次共享的机会。