我想通过checkbox多选一个表中的某几列来显示在dbgrid上,要怎么解决呢?
  主要是adoquery.sql.add(sqlstr)里面的sqlstr不知道该怎么写。因为列可能比较多,如果分一种种情况分别写sqlstr就会很复杂。最简单的方法是什么呢

解决方案 »

  1.   

    放一个TCheckListBox
    选择完成后用一个循环,把TCheckListBox里要显示的列串起来
      

  2.   

    这里有
    自己看吧
     begin
          query1.SQL.Add('Insert Into UserInfo(myUser,myPWD,myIP,myPort,myRequestID,Zt,Ispa,IsAlarm)');
          query1.SQL.Add(' values(:myUser,:myPWD,:myIP,:myPort,:myRequestID,:Zt,:Ispa,:IsAlarm)');
          query1.Params[0].AsString := Edit1.Text;
          query1.Params[1].AsString := Edit2.Text;
          query1.Params[2].AsString :='';
          query1.Params[3].AsInteger:=0;
          query1.Params[4].AsInteger:=0;
          if checkbox3.Checked =true then
          begin
            query1.Params[5].AsBoolean:=true;
          end
          else
          begin
            query1.Params[5].AsBoolean:=false;
          end;
          if checkbox1.Checked =true then
          begin
            query1.Params[6].AsBoolean :=true;
          end
          else
          begin
            query1.Params[6].AsBoolean :=false;
          end;
          if  checkbox2.Checked =true then
          begin
            query1.Params[7].AsBoolean :=true;
          end
          else
          begin
            query1.Params[7].AsBoolean :=false;
          end;
          iQuestion:=application.messagebox('你确定插入记录吗?','插入操作提示信息',mb_yesno);
          if iQuestion=6 then
          begin
            query1.ExecSQL ;
          end;
      

  3.   

    用一个循环在DBGRID.columns[i].visible來实现
      

  4.   

    http://www.tomore.com/1/2324.html
    自己下载看看