在其他窗体中使用主窗体中有关 DBGrid 的命令
我正在制作一个在汽车零部件店使用的简单程序。它应该是这样的: 链接
问题在于左侧的小窗口。当双击主窗口中 DBGrid 中的任何行时,应将其打开,并且应在 DBEdit 字段中显示所有选定项目的特征。如果单击“保存”按钮,它应该将 DBEdit 字段的更改保存到数据库中,否则它应该忽略这些更改。
我使用以下代码双击 DBGrid 中的字段成功打开了另一个表单:
procedure TForm1.DBGrid1DblClick(Sender: TObject);
begin
if not Assigned(Form2)
then Form2 := TForm2.Create(Application);
Form2.Show;
end;
现在唯一的问题是如何让程序检测选择了 DBGrid 中的哪一行,然后在较小窗口的 DBEdit 字段中显示其内容。
谁能告诉我该怎么做吗?
谢谢!
I'm making a simple program for use in automotive parts shop. Here's how it's supposed to look: Link
The problem is the small window on the left. It should be opened when double clicked on any of the rows in DBGrid in the main window, and it should show all of the selected item's characteristics in DBEdit fields. If the Save button is clicked it should save the changes from the DBEdit fields into the database, but otherwise it should just ignore the changes.
I succeeded opening another form by double click on a field in DBGrid by using this code:
procedure TForm1.DBGrid1DblClick(Sender: TObject);
begin
if not Assigned(Form2)
then Form2 := TForm2.Create(Application);
Form2.Show;
end;
The only problem now is how to get the program to detect which row in the DBGrid is selected and then show its contents in DBEdit fields in the smaller window.
Can anyone tell me how to do this, please?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需将
TDBEdits
添加到TForm2
,并将它们连接到DBGrid
所使用的相同DataSource
即可。它们将自动显示在DBGrid
中选择的同一行的内容,您可以编辑或插入到DataSource
的DataSet
中并获得新的或更改的数据自动出现在DBGrid
中。Just add the
TDBEdits
toTForm2
, and connect them to the sameDataSource
as theDBGrid
is using. They will automatically show the contents of the same row that is selected in theDBGrid
, and you can edit or insert into theDataSource's
DataSet
and have the new or changed data appear in theDBGrid
automatically.有很多方法可以实现这一目标。我将描述两个:
,或者
DBGrid1DblClick
中将您想要的任何信息从 Form1 传递到 Form2。这个选项本身就有很多可能性。更新
为了使 DataSource 在 Form2 中可见,请更新单位以使 Form2 的单位使用 Form1 的单位。
There are many ways to achieve this. I'll describe two:
OR
DBGrid1DblClick
from Form1 to Form2. This option, by itself, has many possibilities.Update
For the DataSource to be visible in Form2, unit to make Form2's unit use Form1's unit.