如何在C#中向组合框添加多个项目 [英] How to add multiple items to a Combo Box in C#

查看:112
本文介绍了如何在C#中向组合框添加多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要在组合框中的一行文字上显示多个项目。

Hi All,

I need to display multiple items on one line of text in a combo box.
Such as

"One,a,b
 Two,a,b
 Three,a,b"



虽然comboBox.Items.Add()只允许一个对象,但我希望AddRange()控件

会不会,但是我今天早上似乎没有或者我的GoogleFu弱,因为我做了以下事情:


While the comboBox.Items.Add() only lets one object, I was hoping the AddRange() control
would it, but it doesn't seem to or is my GoogleFu weak this morning as I have done the following:

cboDUTComPort.Items.AddRange(new[] {nameArray[index],"Narf"});



但是每次拆分到一个新行。给予


but this Splits onto a new line each time. giving

nameArray[0]
"Narf"

而不是希望的

rather than the hoped for

nameArray[0], "Narf"





我很接近但是......



I am close but...

推荐答案

你试过:

Have you tried:
cboDUTComPort.Items.Add(string.Join(",", new [] {nameArray[index], "Narf"}));


这篇关于如何在C#中向组合框添加多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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