VB.net 1012将Person的FullName字段绑定到PersonId字段 [英] VB.net 1012 Bind person's FullName field to the PersonId field

查看:121
本文介绍了VB.net 1012将Person的FullName字段绑定到PersonId字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio 2012 VB.net

我开始学习Visual Studio 2005时的一段时间Beth Massi展示了如何将带有IntegerId的文本框绑定到id引用的人的实际名称。她通过将人的FullName数据字段拖到PersonIdTextbox上来做到这一点。



这当然适用于第二个表格中的PersonId,例如TeamCaptain也是TeamMembers表格。



例如,让我们在GameScheduleDatabase中使用以下表格以及GameScheduleDataset:



表1包含了联盟的所有成员。

表名:TeamMembers

Visual Studio 2012 VB.net
Some time back when I started to learn Visual Studio 2005 Beth Massi showed how to bind a textbox with IntegerId to the actual name of the person the id refers to. She did this by dragging the person's FullName datafield onto the PersonIdTextbox.

This would, of course, apply to PersonId in a second table such as a TeamCaptain who is also part of the TeamMembers table.

For example, let's use the following tables in GameScheduleDatabase along with the GameScheduleDataset:

Table 1 contains all the members of the League.
Table Name: TeamMembers

[MemberId]     integer    Not null,
[MemberFirst]  nvarChar   Not null,
[MemberLast]   nvarChar   Not null,
[FullName]     AS         (([Last]+', ')+[First]) PERSISTED NOT NULL,
[Team]         tinyint    Not null       -From TeamId in TeamCaptains table



表2包含团队队长及其助手的姓名

表名:TeamCaptains - 每个队长也是TeamMember表的一部分


Table 2 contains the names of the team captains and their assistants
Table Name: TeamCaptains -- each captain is also part of the TeamMember table

[TeamId]       tinyint    Not Null,      -Primary key
[TeamCaptain]  integer    Not Null,      -from MemberId in TeamMembers table
[Assistant]    integer    Not Null       -from MemberId in TeamMembers table



TeamCaptains表单包含TeamCaptains(详细视图)以及所有团队成员(gridview)工作得很好没问题。



现在问题。 TeamCaptains字段文本框仅显示整数。根据我从Beth Massi的理解,我应该能够将FullName标识符字段拖到TeamCaptainTextbox和AssistantTextbox上,并且正确的名称应该替换整数。



这只是一种作品。

例如:

队长约翰史密斯 - 会员编号35,是队长和团队成员2.

Pocohantis - MemberId 23也属于团队2.由于她是TeamMembers表中第一个属于第2组的人,因此她是在TeamCaptain文本框中显示的人。如果我添加另一个反映实际MemberId的文本框,它仍会显示为35.



我当然意识到,我可以使用绑定到TeamMemberId的另一个文本框以编程方式执行此操作,这很简单。不过,我认为它可以直接在IDE中完成而无需任何编程。



之前我已经完成了,我编写的程序仍然可以工作,但我可以要让它在这里正常工作。我从来没有能够使用gridview,所以任何帮助也会受到赞赏。



我希望这是一个明确的问题。我已经研究了我能想到的一切,但找不到解决方案。

谢谢大家的帮助。


The TeamCaptains form contains the TeamCaptains (detail view) along with all the Members of the team (gridview) Works great with no problem.

Now to the problem. The TeamCaptains field textboxes only show integers. According to What I understood from Beth Massi, I should have been able to drag the FullName identifier field onto the TeamCaptainTextbox and the AssistantTextbox, and the proper name should replace the integer.

It only sort of works.
For example:
Captain John Smith - MemberId 35, is captain and member of team 2.
Pocohantis - MemberId 23 also belongs to team 2. Since she is the first one in the TeamMembers table who belongs to team 2, she is the one that shows in the TeamCaptain textbox. If I add another textbox reflecting the actual MemberId, it still reads 35.

I realize of course, that I can do this programmatically using another textbox bound to the TeamMemberId, and it is simple. Nevertheless, I thought it could be done right in the IDE without any programming whatsoever.

I have accomplished it before, and the program I wrote still works, but I can't get it to work properly here. I have never been able to do it with a gridview, so any help here would also be appreciated.

I hope this is a clear question. I've researched everything I can think of, and can't find the solution.
Thank you all for help.

推荐答案

假设这是winforms,因为我没有看到任何有关Web表单等的参考。



您可以使用数据源窗口进行拖放操作您为数据库添加数据源。您必须更改外键(FK)字段的字段类型,以便它们是组合框。

然后将该组合框绑定到作为查找值的表并将值字段设置为在将显示成员设置为团队成员的名称(例如,在您的情况下为FullName)时实现您的FK内容。



1.创建数据源(视图>项目数据库的其他窗口>数据源

2.对于要编辑的表格,单击数据源中表格的标题,并将类型设置为详细信息。

3.然后展开表树视图​​以查看字段 - 将团队队长和助手的字段类型更改为组合框

4.拖动表格(从表名中拖动)从数据源到获胜形式。它将构建连接

5.然后单击win form designer区域中的每个组合框 - 你会看到一个小的智能标记箭头来获取数据绑定选项(组合框任务弹出) 。

6.对于每个组合框,选中数据绑定框 - 对于数据源,选择具有其名称详细信息的成员的表。 display member是fullName字段。 value member是FK字段(即id或团队队长表中FK字段中的任何内容)。最后,选定的值应该是原始字段(如teamCaptain),但是从主记录的绑定源中选取(而不是查找记录绑定源)。





i认为应该让你非常接近。
Assuming this is winforms, as I don't see any reference about web forms, etc.

You can do your "drag-n-drop" with the datasources window when you add a datasource for your database. You would have to the change the field type for your foreign key (FK) fields so they are combo boxes.
Then bind that combo box to the table that is your lookup values and set the value field to fulfill your FK stuff while setting the display member to be the name of the team member (i.e. FullName in your case).

1. create a datasource (view > other windows > data sources) for your project database
2. for the table you want to edit, click the title of the table in data sources and set the type to "details".
3. then expand the table treeview to see the fields - change the field type for team captain & assistant to be combo boxes
4. drag the table (drag from the table name) from data sources to the win form. it will build the connections
5. then click on each combo box in the win form designer area - you'll see the little "smart tag" arrow to get data binding options (combo box tasks popup).
6. for each combo box, check the box to data bind it - for data source, select the table for the members that has their name details. display member is the fullName field. value member is the FK field (i.e. id or whatever is in the FK field in the team captains table). finally, selected value should be the orginal field (like teamCaptain) but picked from the binding source for the master record (not the lookup record binding source).


i think that should get you pretty close.


这篇关于VB.net 1012将Person的FullName字段绑定到PersonId字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆