如何在组合框上显示2列

人气:608 发布:2022-10-16 标签: mysql vb

问题描述

大家好, 我想知道是否可以在这样的组合框中显示例如ID_REPORT和CLIENT_NAME: -------------------- 1-客户名称v | -------------------- 每个报告都与一个客户端相关联,识别报告的最佳方法是使用客户端名称.对于许多工作人员而言,他们通常按客户名称知道报告,但是他们有一个特殊的代码,因此确实需要该代码. 我尝试过的事情: 我试图简单地将displaymember更改为使用两列,如下所示: cmbReportID.DisplayMember ="ID_REPORT" +-" +"CLIENT_NAME"

Hello guys, I was wondering if it was possible to show for example ID_REPORT and CLIENT_NAME on a combobox like this: -------------------- 1 - Client name v | -------------------- Every report is associated with a client, and the best way to identify the reports are by using the client name. For many of the workers, they usually know the reports by client name, but they have a special code, and that code is really needed. What I have tried: I''ve tried to simply change the displaymember to use both columns like so: cmbReportID.DisplayMember = "ID_REPORT" + "-" + "CLIENT_NAME"

推荐答案

如注释中所述,最简单的解决方案是修改SQL查询以添加组合值作为计算列: As discussed in the comments, the simplest solution is to modify the SQL query to add the combined value as a computed column:
SELECT 
    ID_REPORT, 
    CLIENT_NAME, 
    Convert(varchar(50), ID_REPORT) + ' - ' + CLIENT_NAME As DisplayName 
FROM 
    ...

然后,将显示成员设置为计算列的名称:

You then set the display member to the name of the computed column:

cmbReportID.DisplayMember = "DisplayName"

580