Combobox with multiple columns

↘锁芯ラ 提交于 2019-12-19 10:01:47

问题


Scenario: I am in the process of moving an application from access to C# and on one of the forms(in access) the user is able to select a drop down that has 3 columns (ID, FirstName, LastName). Once they select from the list the ID is displayed on the drop down.

Question: Is it possible to recreate this functionality using a combo box? What alternatives can you suggest?

EDIT:

alt text http://www.freeimagehosting.net/uploads/7acfb7bb8b.jpg

Dropdown is on the top left, a text box is next to it that uses the name from the last two columns of the dropdown

EDIT 2:

Since the multiple columns arent feasible is there a way to specify mutiple displaymembers to show up on the dropdown instead? For Example: ID - FirstName LastName

Currently a employee object is being added to the dropdown with those properties. I tried setting display member to

cmbEmp.DisplayMember ="EmployeeID " + "FirstName " + "LastName";

but that doesn't. Should I scrap using the employee object and just make a SQL call grabbing those concatenated together? I was attempting to reuse some code (I was given this project halfway through its completion) but it may not be feasable.


回答1:


The common method of achieving this is overriding the onDropDown event to draw your own dropdown window with multiple values. There's plenty of examples out there ranging from walkthroughs to downloadable controls. Here's a few:

  • http://www.codeguru.com/cpp/controls/combobox/multicolumncombos/article.php/c1825/
  • http://www.codeproject.com/KB/combobox/multicolumncombo.aspx
  • http://www.codeproject.com/KB/combobox/Multicolumn_ComboBox.aspx
  • http://www2.syncfusion.com/library/classref/Syncfusion.Windows.Forms.Tools.MultiColumnComboBox.html
  • http://www.brothersoft.com/downloads/multicolumn-combobox.html
  • http://www.edneeis.com/control.aspx?ID=7



回答2:


From your image combo box does not directly have that capability, however I have seen custom 3rd party controls that do it. I will update if I can find the name of one.

The software I used had a license of http://www.active-x.com/ActiveX/APEX_Software_Corporation/True_DBList_Pro_5_0/ However this program was written in the days of VB5 (I am not sure if the company that makes the control exists anymore). I'd advise try to find something similar but more up to date.



来源:https://stackoverflow.com/questions/3189132/combobox-with-multiple-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!