本文介绍了在Listview中对列进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚接触c#
我已经制定了一个客户经理计划.我有两种形式,第一种是我的列表视图,另一种是您在其中键入客户信息(姓名,国家/地区等)的地方
我想在不同的列中排序
看这里,您会了解
http://imageshack.us/f/717/skiten1.png/ [ ^ ]
这是一些代码,也许我不知道还不够.
Form1
Im pretty new to c#
I have made a customer manager program. I have two forms, the first is my listview and the other is where you type in the information of the customer(name, country, etc)
I want to sort in the diffrent columns
Look here and you will understand
http://imageshack.us/f/717/skiten1.png/[^]
Here is some code, maybe it''s not enough i dont know.
Form1
InitializeComponent();
listView1.View = View.Details;
listView1.LabelEdit = true;
listView1.AllowColumnReorder = true;
listView1.FullRowSelect = true;
listView1.GridLines = true;
listView1.Sorting = SortOrder.Ascending;
listView1.FullRowSelect = true;
listView1.Columns.Add("ID", 300, HorizontalAlignment.Left);
listView1.Columns.Add("Name", 70, HorizontalAlignment.Left);
listView1.Columns.Add("Zipcode", 70, HorizontalAlignment.Left);
listView1.Columns.Add("City", 100, HorizontalAlignment.Left);
listView1.Columns.Add("Country", 100, HorizontalAlignment.Left);
listView1.Columns.Add("Phone", 100, HorizontalAlignment.Left);
listView1.Columns.Add("Email", 100, HorizontalAlignment.Left);
Form1
Form1
private void MainForm_Load(object sender, EventArgs e)
{
if (customerframe.ShowDialog() == DialogResult.OK) //if button OK is clicked then value will be inserted
{
// var item = string.Format("[{0}]",contact.ToString());
listView1.Items.Add(string.Format("[{0}]", customerframe.ToString()));
}
}
Form2
Form2
private void btnOk_Click(object sender, EventArgs e)
{
// inside contact
contact.FirstName = tbFirstName.Text;
firstName = contact.FirstName;
contact.LastName = tbLastName.Text;
lastName = contact.LastName;
contact.PhoneData = new CustomerFiles.Phone(tbCellPhone.Text);
phone = contact.PhoneData;
contact.PhoneData = new CustomerFiles.Phone(tbHomePhone.Text);
email = contact.EmailData;
//inside address class
address.City = tbCity.Text;
city = address.City;
address.country = cbCountry.Text;
//address.Country = new CustomerFiles.Countries(cbCountry.Text);
// countryinfo = address.Country;
address.Street = tbStreet.Text;
street = address.Street;
address.ZipCode = tbZipCode.Text;
zipcode = address.ZipCode;
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void tbFirstName_TextChanged(object sender, EventArgs e)
{
if (tbFirstName.Text != string.Empty)
{
contact.FirstName = tbFirstName.Text;
}
else
MessageBox.Show("You must fill in your first name");
tbFirstName.Focus();
}
Form2
Form2
public override string ToString()
{
return string.Format("[{0}, {1}, {2}]", contact.ToString(), address.ToString(), country.Name);
}
推荐答案
这篇关于在Listview中对列进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!