1.利用AdoConnect+AdoQuery链接SqlServer查询数据

int i,j,col,row;UnicodeString strSQL;strSQL = " select * from viewBasicLensProblem";adoquery->Close();adoquery->SQL->Clear();adoquery->SQL->Add(strSQL);adoquery->Open();col = qryBasic->FieldCount;row = qryBasic->RecordCount;strGrid1->ColCount = col;strGrid1->RowCount = row+1;for (i =1; i < row+1; i++){for ( j =0; j< col; j++){strGrid1->Cells[j][i] = qryBasic->Fields->Fields[j]->AsString;}qryBasic->Next();}

2.AdvStringGrid合并行和列

   strGrid1->MergeCols(3,4);        //合并列strGrid1->MergeCells(0,0,2,2);   //合并行/*MergeCols(col,row);mergeCells(col,row,c,d) 单元格合并函数col 单元格的列号row 单元格的行号c 从单元格[col,row]起,向下合并的列数d 从单元格[col,row]起,向下合并的行数*/
  附:重绘表格 strGrid->OnDrawCell()
void __fastcall TForm1::strGrid1DrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect,TGridDrawState State)
{//重绘int c1 = 0, r1 = 0, c2 =1 , r2 =1 ;if (ACol>=c1 && ACol<=c2 && ARow>=r1 && ARow <= r2){TRect rect1 = strGrid1->CellRect(c1,r1);TRect rect2 = strGrid1->CellRect(c2,r2);TRect rect  = TRect(rect1.left,rect1.top,rect2.left-1,rect2.bottom-1);TStringGrid *grid =(TStringGrid*)Sender;TCanvas*canvas = grid->Canvas;canvas->FillRect(rect);canvas->Pen->Color = clBlack;canvas->MoveTo(rect.left,rect.top);canvas->LineTo(rect.right,rect.bottom);canvas->MoveTo(rect.left,rect.bottom);canvas->LineTo(rect.right,rect.top);canvas->TextOut(rect.left + rect.Width()/2-canvas->TextWidth("CombineGrids")/2,rect.top  + rect.Height()/2 - canvas->TextHeight("CombineGrids")/2,"CombineGrids");}
}
void __fastcall TForm1::strGrid1DrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect,TGridDrawState State)
{//隔行换背景色if(ARow>0){if(ARow%2 == 0){strGrid1->Canvas->Brush->Color = clWhite;strGrid1->Canvas->FillRect(Rect);strGrid1->Canvas->Font->Color = clBlue;}else{strGrid1->Canvas->Brush->Color = clCream;strGrid1->Canvas->FillRect(Rect);}DrawText(strGrid1->Canvas->Handle, strGrid1->Cells[ACol][ARow].c_str(),-1, (RECT*)&Rect, DT_SINGLELINE | DT_VCENTER | DT_CENTER);}if(ARow==0)//对标题行操作
    {int wwd=strGrid1->Canvas->TextWidth(strGrid1->Cells[ACol][ARow]);//获取文本长度int colwd=strGrid1->ColWidths[ACol];//获取列宽colwd+=2;  //一般开始留几个像素int ww=(colwd-wwd)/2; //文本开始位置if(ww<0)ww=0;strGrid1->Canvas->Brush->Color=clWhite;strGrid1->Canvas->Brush->Style=bsSolid;strGrid1->Canvas->Rectangle(Rect.Left+2,Rect.Top+2,Rect.Right,Rect.Bottom);strGrid1->Canvas->TextOut(Rect.Left+ww,Rect.Top+4,strGrid1->Cells[ACol][ARow]);}
}

2.1多表头

//多表头strGrid1->Multilinecells = true;strGrid1->MergeCells(0,0,2,1);strGrid1->Alignments[0][0] = taCenter;strGrid1->Cells[0][0] = "中国";strGrid1->Cells[0][1] = "福建";strGrid1->Cells[1][1] = "北京";
   
//多表头strGrid1->FixedRows = 2;  //固定行数strGrid1->SaveFixedCells = false;strGrid1->MergeCells(1,0,2,1);strGrid1->MergeCells(3,0,2,1);strGrid1->Cells[1][0]="Title1";strGrid1->Cells[1][1]="Brand";strGrid1->Cells[2][1]="Type";strGrid1->Cells[3][1]= "CC";strGrid1->Cells[4][1]= "Pk";strGrid1->Cells[3][0]= "Title2";strGrid1->BtnEdit->ButtonWidth = 24;

2.2

IsFixedCell()

void __fastcall TForm1::strGrid1IsFixedCell(TObject *Sender, int ARow, int ACol, bool &IsFixed){if (ACol==5||ACol==2){IsFixed = true;}
}

3.常用属性设置

http://www.cnblogs.com/JackSun/archive/2010/12/16/1908119.html

是否能对特定的单元格进行编辑 
      用TAdvStringGrid::OnCanEit()事件句柄来处理,
      设置bool &canedit参数来达到能否编辑某些单元格的效果

隐藏和显示某些单元格
      TAdvStringGrid:: UnHideColumn(int ACol)
      TAdvStringGrid::HideColumn(int ACol);

strGrid1->Options = strGrid1->Options<<goEditing;//可编辑
strGrid1->Options = strGrid1->Options>>goEditing;//只读
strGrid1->Options = strGrid1->Options<<goTabs;  //控制是否可用TAB键将光标移到下一CELL
strGrid1->Options =strGrid1->Options<<goColSizing;

4.OnGetEditorType()更改cell样式

void __fastcall TForm1::strGrid1GetEditorType(TObject *Sender, int ACol, int ARow,TEditorType &AEditor)
{switch(ACol){case 1:AEditor = edComboList; break;case 2:AEditor = edEditBtn;   break;case 3:AEditor = edSpinEdit;  break;case 4:AEditor = edDateEdit;  break;}//增加edComboEdit和edComboList的下拉列表:strGrid1->ClearComboString();strGrid1->AddComboString("List1");strGrid1->AddComboString("List2");strGrid1->AddComboString("List3");strGrid1->Combobox->Sorted = true; //排序
}

//增加Checkbox//设置StringGrid->Options->goEditing = true;//stringGrid->enableGraphics = true;//OnFormCreate()for (int i = 1; i < strGrid1->RowCount-1; i++){strGrid1->AddCheckBox(0,i,false,false);//0表示col[0]
    }bool bChecked;//读取checkbox状态for (int j=0; j<strGrid1->RowCount-1; j++){strGrid1->GetCheckBoxState(1,j,bChecked);if (bChecked){ShowMessage("已勾选");}else{ShowMessage("未勾选");}}//设置checkbox状态for (int i=1; i<strGrid1->RowCount-1; i++){if (bChecked){strGrid1->SetCheckBoxState(0,i,false);}else{strGrid1->SetCheckBoxState(0,i,true);}}

5.结点和过滤

void __fastcall TForm1::btn1Click(TObject *Sender)
{//添加结点strGrid1->FixedCols = 0;strGrid1->FixedColWidth = 20;strGrid1->AddNode(2,3);strGrid1->AddNode(4,2);//strGrid->AddNode(int ARow,int ASpan) Span--分组的跨越度
}void __fastcall TForm1::btn2Click(TObject *Sender)
{//打开所有结点strGrid1->ExpandAll();strGrid1->CellNode->NodeType = cnFlat;
//    strGrid1->CellNode->NodeType = cn3D;
//    strGrid1->CellNode->NodeType = cnGlyph;//收缩所有节点strGrid1->ContractAll();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btn3Click(TObject *Sender)
{//过滤TFilterData *fd;strGrid1->Filter->Clear();fd = strGrid1->Filter->Add();fd->Condition = cbb1->Items->Strings[cbb1->ItemIndex];//fd->Column = 1;if (cbb2->ItemIndex !=NULL){fd = strGrid1->Filter->Add();fd->Condition=cbb2->Items->Strings[cbb2->ItemIndex];}//fd->Column = 3;strGrid1->FilterActive=true;
}

6.fastReport详解

转载于:https://www.cnblogs.com/marlbora/p/4118736.html

了解AdvStringGrid相关推荐

  1. AdvStringGrid 垂直居中 、水平居中

    官网faq,解答: 结果: 转载于:https://www.cnblogs.com/del88/p/6835162.html

  2. AdvStringGrid 复选框、goRowSelect

    varI: Integer; beginfor I := 1 to 48 dobeginAdvStringGrid1.AddCheckBox(0, I, True, True);AdvStringGr ...

  3. Delphi 如何用TMS AdvStringGrid做财务会计记账凭证的多表头网格表格?

    Delphi多表头财务会计记账凭证 郑重提示:本文代码来自Delphi盒子中的用户:kenliaoliao (ben)  感谢kenliaoliao (ben)对Delphi社区的贡献!欢迎加入Del ...

  4. delphi7在AdvStringGrid中添加ComboBox方法,记录下来

    1.stringgrid1添加onGetEditorType事件 procedure TForm1.stringgrid1GetEditorType(Sender: TObject; ACol,   ...

  5. Delphi7.0破解及常用三方控件的安装

    (董氏门生专用) 1 Delphi7.0安装及破解 1)点击安装包进行安装 2)当需要输入key时,使用keygen.exe获得 3)当出现"Install InterBase Client ...

最新文章

  1. python使用matplotlib可视化线图(line plot)、将可视化图像的图例(legend)放置在图像外部、底部区域
  2. 看到OSC有一期是:“OSChina 第 37 期高手问答 —— 消息队列服务”
  3. 调试css的新装备--IETester
  4. linux中fork, source和exec的区别
  5. python 修改模板对象的属性_django小技巧之html模板中调用对象属性或对象的方法...
  6. HarmonyOS之深入解析视频的功能和使用
  7. 2021-10-28嵌入式人工智能
  8. 5中sender方法介绍_【成长】开学第一次自我介绍如何作?5步方法留下好印象受益5年...
  9. c++学习笔记(15) 异常处理
  10. Linux编程(5)_静态库与动态库
  11. java dao修改语句_一个通用的DAO模型实现增删改查
  12. 使用el-checkbox实现全选,点击失效没有反应 1
  13. Android Studio中使用android:src=quot;@drawable/ic_launcherquot;报错
  14. Modifier源码总结
  15. java开发中推荐的防御sql注入方法_Java防止SQL注入
  16. 数学规划模型(三):整数规划模型
  17. Linux安装-CentOS6.x
  18. Redis批量操作--增加,删除,模糊查询
  19. 工商银行u盾 java_中国农业银行的“K宝”、中国工商银行的“U盾”、中国建设银行的“网银盾”属于网上银行的( )类安全技术措施...
  20. 傻瓜式制作在线热力图!只需三个步骤即可学会热力图的制作

热门文章

  1. webalizer日志分析软件的安装
  2. POJ-1436 线段树 区间更新
  3. DetachedCriteria 分页Projection取消聚合条件
  4. VC中BSTR和CString的使用
  5. 分享python os.system一点心得
  6. [性能优化]UITableView性能优化的一点感悟及计算UILabel高度的新方法
  7. 小论Java类变量的隐私泄露
  8. 第4章 玩转数学公式
  9. Xcode6中添加pch文件
  10. DHTML【2】--HTML