最近刚刚从ASP转过来研究.net(c#),先搞一个简单的东东看看,遇到以下问题:
combobox相关代码//定义一个类
public class Dropselect
{
public Dropselect(int id, string skey, string title)
{
this.Id=id;
this.Skey=skey;
this.Title=title;
}
public int Id;
public string Skey;
public string Title;
}//将选项添加进去
this.comboBox5.Items.AddRange(new object[] {
new Dropselect(0,"xx","-条件1-"),
new Dropselect(1,"FBillNo","订单号"),
new Dropselect(2,"FDeptId","部 门"),
new Dropselect(3,"FEmpId","业务员"),
new Dropselect(4,"FModel","型 号"),
new Dropselect(5,"FItemId","品 牌"),
new Dropselect(6,"FCustId","客 户")});
this.comboBox5.DisplayMember = "Title";
this.comboBox5.ValueMember = "Skey";VS没有报错,可运行出来显示的是"WindowsFormsApplication1.MainFrame.Dropselect"
不知道怎么回事?
combobox相关代码//定义一个类
public class Dropselect
{
public Dropselect(int id, string skey, string title)
{
this.Id=id;
this.Skey=skey;
this.Title=title;
}
public int Id;
public string Skey;
public string Title;
}//将选项添加进去
this.comboBox5.Items.AddRange(new object[] {
new Dropselect(0,"xx","-条件1-"),
new Dropselect(1,"FBillNo","订单号"),
new Dropselect(2,"FDeptId","部 门"),
new Dropselect(3,"FEmpId","业务员"),
new Dropselect(4,"FModel","型 号"),
new Dropselect(5,"FItemId","品 牌"),
new Dropselect(6,"FCustId","客 户")});
this.comboBox5.DisplayMember = "Title";
this.comboBox5.ValueMember = "Skey";VS没有报错,可运行出来显示的是"WindowsFormsApplication1.MainFrame.Dropselect"
不知道怎么回事?
解决方案 »
- 怎么获dataGridView中的数据
- xna中的虚拟人
- 又来送分哦
- 我把C#程序集编译成dll,有没有办法让这个dll脱离donet框架?
- 我误按下某个快捷键后,Visual Stuio将Tab和空格都显示出来了,如何不显示?
- 上海出名软件公司面试题(hashtable,dictionary 从原理上说说有什么异同,哪个性能高一些?)
- 请问这句LAMBDA表达式形式的语句如果用LINQ来表达
- 今天USER過來測試,提出一個C# win form 中實現焦點自動跳轉的問題!
- 请教一个问题:在制作WINDOWS APP安装程序的时候,我要在用户选定安装路径后修改用户注册表,应该怎么操作?
- [19] [winform] 如何控件由 Splitter 分割的几个区域的比例?
- 求替换关键字 (一行一个)如何写
- 关于vs2010的一些问题
public class Dropselect
{
public override string ToString()
{
return Title;
}
public Dropselect(int id, string skey, string title)
{
this.Id=id;
this.Skey=skey;
this.Title=title;
}
public int Id;
public string Skey;
public string Title;
}
办法二
public class Dropselect
{
public Dropselect(int id, string skey, string title)
{
this.Id=id;
this.Skey=skey;
this.Title=title;
}
public int Id { get; set; }
public string Skey { get; set; }
public string Title { get; set; }
}
例如:combobox.text.tostring()这是返回显示的项
string s = combobox1.SelectedValue.tostring();
还是不行,我用Messagebox.show(combobox1.SelectedValue.Tostring());提示未将对象引用设置到对象的实例
调试了一下,还是string s = combobox1.SelectedValue.ToString();这句异常,会不会前面ValueMember没有数值?