嗨,我有不同勢列編號,姓名,郵編列表視圖,城市,國家,電話,電子郵件 和我有兩種形式,Form 1和Form排序項
在第一種形式我有列表視圖與列 在第二種形式我有不同勢列表框自定義的經理在那裏你可以輸入客戶信息(如姓名,郵編,城市等)
我想在窗體2的信息後進行排序Form1中的列。例如Form2中的「名稱」Texbox應插入Form1列表視圖的列名稱下,並且應在Zipcode列下插入文本框Zipcode文本。
picture http://img717.imageshack.us/img717/3486/skiten1.png
這很難,因爲一個初學者的IM點點,並按照不同勢的網站並沒有幫助我。
請問我該怎麼辦。
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);
窗體2
private void btnOk_Click(object sender, EventArgs e)
{
contact.FirstName = tbFirstName.Text;
firstName = contact.FirstName;
contact.LastName = tbLastName.Text;
lastName = contact.LastName;
窗體2
private void btnOk_Click(object sender, EventArgs e)
{
MainForm main = new MainForm();
contact.FirstName = tbFirstName.Text;
firstName = contact.FirstName;
contact.LastName = tbLastName.Text;
lastName = contact.LastName;
仍然窗體2
public override string ToString()
{
return string.Format("[{0}]", contact.ToString());
}
//這裏談到的Contact類
class Contact
{
private string firstName;
private string lastName
在聯繫人類也有上述變量的屬性,然後這樣
public override string ToString()
{
return string.Format("[{0}, {1}, {2}, {3}]", firstName, lastName);
}
Form1中
private void MainForm_Load(object sender, EventArgs e)
{
ColumnHeader columnheader;
ListViewItem listviewitem;
// Ensure that the view is set to show details.
listView1.View = View.Details;
if (customerframe.ShowDialog() == DialogResult.OK) //if button OK is clicked then value will be inserted
{
listviewitem = new ListViewItem(contact.FirstName);
listviewitem.SubItems.Add(contact.LastName);
this.listView1.Items.Add(listviewitem);
一個ToString我真的不知道你需要多少代碼來幫助我,而且,我的代碼非常混亂
嗯這樣做時,我得到的ListView空項目 '如果(customerframe.ShowDialog()== DialogResult.OK) { listviewitem = new ListViewItem(contact.FirstName); listviewitem.SubItems.Add(contact.LastName); listviewitem.SubItems.Add(address.ZipCode); this.listView1.Items.Add(listviewitem); }' – user1067973
@ user1067973您發佈的代碼不顯示form1和form2之間的關係。他們怎麼和對方說話? – LarsTech
我在我的帖子中放了一些代碼,也許這可以讓你幫我 – user1067973