请教combobox的问题

skyaspnet 2009-10-18 06:24:45
请教combobox如何实现dropdownlist的动态添加item的功能,包括同时设置text和value属性

谢谢!
...全文
72 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
skyaspnet 2009-10-18
  • 打赏
  • 举报
回复
感谢大家
wuyq11 2009-10-18
  • 打赏
  • 举报
回复
ComboBox1.Items.Add("item");
ComboBox1.Items["item"].Value = "value";
ComboBox1.Items["item"].Text = "Text";
ComboBox1.Items.Insert(0, new ListItem("", ""));

combobox实例
yulinlover 2009-10-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 caozhy 的回复:]
C# codeusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace Windows¡­
[/Quote]
同意
yankunlin 2009-10-18
  • 打赏
  • 举报
回复
学习了.......
threenewbee 2009-10-18
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{

public class CboItem
{
public string Text { get; set; }

public string Value { get; set; }

public CboItem(string t, string v)
{
Text = t;
Value = v;
}

public override string ToString()
{
return Text;
}
}

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
comboBox1.Items.Add(new CboItem("ttt", "vvv"));
}
}
}
skyaspnet 2009-10-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 caozhy 的回复:]
貌似很简单的问题。
高手提问
莫非我理解错了?
[/Quote]

不是高手,没怎么用过这个控件,看哪位大侠用过指点一下,找了一些方法,但是没找到在代码里一次设置的办法
threenewbee 2009-10-18
  • 打赏
  • 举报
回复
貌似很简单的问题。
高手提问
莫非我理解错了?

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧