使combox信息出现在列表视图中 [英] To make combox info appear in listview
问题描述
您好,我正在尝试制作客户经理程序.而且我想插入他/她来自哪个国家,但是我无法在ListView中显示国家信息.
我有一个Form1 = mainForm类
和Form2 = CustomerFrame类
MainForm = listview
CustomerFrame =您在其中键入名称,电话号码等信息的信息
在CustomerFrame内部
Hi im trying to make a customer manager program. And i want to insert which countries he/she is from but i can not make the country information show in my ListView.
I have a Form1 = mainForm class
and Form2 = CustomerFrame class
MainForm = listview
CustomerFrame = where you type info like name, phone nr, etc
inside CustomerFrame
internal CustomerFiles.Countries countryinfo {get; set;}
address.Country = new CustomerFiles.Countries(cbCountry.Text);
countryinfo = address.Country;
public override string ToString()
{
return string.Format("[{0}, {1}]",contact.ToString(), address.ToString());
}
//在国家/地区内部类
//inside Countries class
class Countries
{
public int CountryId { get; set; }
public string Name { get; set; }
public Countries()
{
}
public Countries(string x)
{
}
}
内部地址类
inside Adress class
class Address
{
public Countries country;
}
}
get
{
return country;
}
set
{
country = value;
public override string ToString()
{
return string.Format("[{0}, {1}, {2}, {3}]", city, zipCode, country, street);
}
在MainForm内
inside MainForm
private void MainForm_Load(object sender, EventArgs e)
{
if (customerframe.ShowDialog() == DialogResult.OK) {
listView1.Items.Add(String.Format("[{0}]", customerframe.ToString()));
}
}
当尝试选择国家/地区时,我会在列表视图中看到"CustomerRegister1.CustomerFiles.Countries"而不是国家/地区名称.我该怎么办,解决方案是什么?在此先感谢
when trying to choose a country i get this in my listview"CustomerRegister1.CustomerFiles.Countries" instead of the country name. What can i do, whats the solution to this?! Thanks in advance
推荐答案
您直接绑定表单对象.这就是为什么您遇到此问题的原因.您必须绑定属性国家/地区.这样可以解决您的问题.
如果需要进一步的说明,请查看下面的链接..
http://doitdotnet.wordpress.com/2011/12/16/pass -data-between-two-winforms/ [
Hi,
You are directly binding the Form Object. That''s why you are getting this issue.. You have to bind the property country instead. This will solve your problem.
Have a look at the below link if you need further clarifications..
http://doitdotnet.wordpress.com/2011/12/16/pass-data-between-two-winforms/[^]
Thanks
这篇关于使combox信息出现在列表视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!