ToolSrip的ComboBox没有datasourse属性,应该怎么帮他设置Text值和Value值 IList<CourseInfo> courseList = CourseManage.GetAllCourse();
foreach (CourseInfo courseinfo in courseList)
{
tsCboCourse.Items.Add(courseinfo.CName);
}
这只是设置ComboBox的Text值,怎么再设置它的Value值呢?
foreach (CourseInfo courseinfo in courseList)
{
tsCboCourse.Items.Add(courseinfo.CName);
}
这只是设置ComboBox的Text值,怎么再设置它的Value值呢?
private void Form3_Load(object sender, EventArgs e)
{
for (int i = 0; i < 5; i++)
{
toolStripComboBox1.Items.Add(new TVclass(i + "text", i));
} //((TVclass)toolStripComboBox1.SelectedItem).Value就能拿到他的值
}
public class TVclass
{
public TVclass(string text, int value)
{
this.text = text;
this.value = value; }
string text;
int value; public int Value
{
get { return this.value; }
set { this.value = value; }
} public string Text
{
get { return text; }
set { text = value; }
} public override string ToString()
{
return text;
}
}
public override string ToString()
{
return text;//返回显示的值 }