***这个功能如何实现???***

Snakeguo 2002-01-15 02:54:34
我要实现以下功能,哪位能提供解决方案与源代码?
把目标数据表的内容罗列出来,让用户选择,可多选(通过CheckBox或者别的,有点类似于CheckListBox),然后返回目标数据表中的一个或多个字段的值
...全文
99 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
Snakeguo 2002-01-18
  • 打赏
  • 举报
回复
Snakeguo 2002-01-17
  • 打赏
  • 举报
回复
为什么不能踢前呀?
Snakeguo 2002-01-16
  • 打赏
  • 举报
回复
谢谢,还有没有别的办法?
zzd 2002-01-15
  • 打赏
  • 举报
回复
根据选定的字段名称,动态生成SQL语句,一切OK!
wslmwslm 2002-01-15
  • 打赏
  • 举报
回复
特别有用的信息, ListBox1.Items.Strings[ListBox1.ItemIndex]; 自己研究吧,哈!
bluetooth_2001 2002-01-15
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB;

type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
ListBox1: TListBox;
Button2: TButton;
ListBox2: TListBox;
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
var
temp:string;
begin

end;

procedure TForm1.Button2Click(Sender: TObject);//取得字段
var
temp:string;
i:integer;
begin
ListBox1.Clear;
for i:=0 to ADOTable1.FieldCount-1 do
begin
temp:=ADOTable1.FieldDefList.FieldDefs[i].Name;
ListBox1.Items.Add(temp);
end;
end;

procedure TForm1.Button1Click(Sender: TObject); //显示用户选择的字段
var
temp:Tstringlist;
i:integer;
begin
DBGrid1.Columns.Clear;
temp:=TstringList.Create;
temp.Add(ListBox1.Items.DelimitedText);
for i:=0 to ListBox1.Items.Count-1 do
if (ListBox1.Selected[i]) then
begin

DBGrid1.Columns.add.FieldName:=ListBox1.Items[i];
ListBox2.Items.Add(ListBox1.Items[i]);
end;

end;

end.
bluetooth_2001 2002-01-15
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB;

type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
ListBox1: TListBox;
Button2: TButton;
ListBox2: TListBox;
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
var
temp:string;
begin

end;

procedure TForm1.Button2Click(Sender: TObject);//取得字段名,让用户选择
var
temp:string;
i:integer;
begin
ListBox1.Clear;
for i:=0 to ADOTable1.FieldCount-1 do
begin
temp:=ADOTable1.FieldDefList.FieldDefs[i].Name;
ListBox1.Items.Add(temp);
end;
end;

procedure TForm1.Button1Click(Sender: TObject); //显示用户选择的字段名
var
temp:Tstringlist;
i:integer;
begin
DBGrid1.Columns.Clear;
temp:=TstringList.Create;
temp.Add(ListBox1.Items.DelimitedText);
for i:=0 to ListBox1.Items.Count-1 do
if (ListBox1.Selected[i]) then
begin

DBGrid1.Columns.add.FieldName:=ListBox1.Items[i];
ListBox2.Items.Add(ListBox1.Items[i]);
end;

end;

end.
thedream 2002-01-15
  • 打赏
  • 举报
回复
procedure TForm1.Button1Click(Sender: TObject);
var
i,p,selectcount:integer;
begin
p:=0;
dbgrid1.Columns.Clear;
for i:=0 to componentcount-1 do begin
if Components[i] is Tcheckbox then
if Tcheckbox(Components[i]).checked then begin
dbgrid1.Columns.Add;
dbgrid1.Columns[p].fieldname:=Tcheckbox(Components[i]).caption;
//你可以把fieldname的值写到checkbox的hint里面,我这里是用的caption;
inc(p);
end;
end;

end;
fengerfeifei 2002-01-15
  • 打赏
  • 举报
回复
通过TDataBase可以得到其中每个表的每个字段名(是一个函数,输入表名返回一个TString的字段列表)。做一选择列表让用户选,
选中的就在对应的TDataSet中用DataSetX.FieldByName('名字').Visible:=true;
没有选中的就DataSetX.FieldByName('名字').Visible:=false;
这样相关联的DBGrid里面就会是显示选中的字段。
当然,选中的字段信息要保存到一个地方。可以放到ini文件也可以放到数据库中的一个表里面。没做这不下次使用又会变成以前的样子。
edguo 2002-01-15
  • 打赏
  • 举报
回复
SMDBGrid带CheckBox,MultiSelect比DBGrid方便多。
踢踏 2002-01-15
  • 打赏
  • 举报
回复
DBGrid也可以的
edguo 2002-01-15
  • 打赏
  • 举报
回复
找个好一点的DBGrid就能解决你这个问题
例如免费的SMDBGrid,还行,虽然有点bug.

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧