通过“添加”页面进入到这个listview,上面显示有刚才的添加数据,我怎么做可以做到我选中listview中的某行,然后点击修改回到当时添加这行数据的页面,然后在里面修改,最后在listview中显示修改后的数据

解决方案 »

  1.   

    添加跳listview的时候,在跳的同时把添加数据更新过来,在点种某行修改,进入到添加这行数据的页面(将添加后的数据读取出来就OK了),然后修改,把修改结果在listview中刷新一下。如果你想修改按钮直接修改完,然后刷新到listview中的话,就在跳到修改页面的时候,同时把listview的对象传过来,然后修改完成以后,在调用刚刚传过来的这个对象的对应的刷新方法。不过要注意,一定是你已经打开的listview对象,而不能NEW
      

  2.   

    楼主可以在修改窗口定义委托然后主窗口使用委托下面是简单的TextBox传值 楼主可以根据自己的需求改成listview应该很好改下面为代码form1.cs代码
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                Form2 f2 = new Form2();
                f2.Update_Complete += new Form2.UpdateComplete(f2_Update_Complete);
                f2.Value = textBox1.Text;
                f2.ShowDialog();
            }        void f2_Update_Complete(string UpdateValue)
            {
                textBox1.Text = UpdateValue;
            }    }
    }Form1界面代码:
    namespace WindowsFormsApplication1
    {
        partial class Form1
        {
            /// <summary>
            /// 必需的设计器变量。
            /// </summary>
            private System.ComponentModel.IContainer components = null;        /// <summary>
            /// 清理所有正在使用的资源。
            /// </summary>
            /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }        #region Windows 窗体设计器生成的代码        /// <summary>
            /// 设计器支持所需的方法 - 不要
            /// 使用代码编辑器修改此方法的内容。
            /// </summary>
            private void InitializeComponent()
            {
                this.button1 = new System.Windows.Forms.Button();
                this.textBox1 = new System.Windows.Forms.TextBox();
                this.SuspendLayout();
                // 
                // button1
                // 
                this.button1.Location = new System.Drawing.Point(106, 203);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(75, 23);
                this.button1.TabIndex = 0;
                this.button1.Text = "button1";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.button1_Click);
                // 
                // textBox1
                // 
                this.textBox1.Location = new System.Drawing.Point(106, 117);
                this.textBox1.Name = "textBox1";
                this.textBox1.Size = new System.Drawing.Size(100, 21);
                this.textBox1.TabIndex = 1;
                this.textBox1.Text = "Test";
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(292, 266);
                this.Controls.Add(this.textBox1);
                this.Controls.Add(this.button1);
                this.Name = "Form1";
                this.Text = "Form1";
                this.ResumeLayout(false);
                this.PerformLayout();        }        #endregion        private System.Windows.Forms.Button button1;
            private System.Windows.Forms.TextBox textBox1;
        }
    }
    From2代码using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication1
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }        public delegate void UpdateComplete(string UpdateValue);
            public event UpdateComplete Update_Complete;
            public string Value;
                        private void button1_Click(object sender, EventArgs e)
            {
                if (Update_Complete != null)
                {
                    Update_Complete(textBox1.Text);
                }
                this.Close();
            }        private void Form2_Load(object sender, EventArgs e)
            {
                textBox1.Text = Value;
            }
        }
    }Form2界面代码:
    namespace WindowsFormsApplication1
    {
        partial class Form2
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;        /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }        #region Windows Form Designer generated code        /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.textBox1 = new System.Windows.Forms.TextBox();
                this.button1 = new System.Windows.Forms.Button();
                this.SuspendLayout();
                // 
                // textBox1
                // 
                this.textBox1.Location = new System.Drawing.Point(85, 81);
                this.textBox1.Name = "textBox1";
                this.textBox1.Size = new System.Drawing.Size(100, 21);
                this.textBox1.TabIndex = 0;
                // 
                // button1
                // 
                this.button1.Location = new System.Drawing.Point(85, 163);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(75, 23);
                this.button1.TabIndex = 1;
                this.button1.Text = "更新";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.button1_Click);
                // 
                // Form2
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(292, 266);
                this.Controls.Add(this.button1);
                this.Controls.Add(this.textBox1);
                this.Name = "Form2";
                this.Text = "Form2";
                this.Load += new System.EventHandler(this.Form2_Load);
                this.ResumeLayout(false);
                this.PerformLayout();        }        #endregion        private System.Windows.Forms.TextBox textBox1;
            private System.Windows.Forms.Button button1;
        }
    }
      

  3.   

    对了我用的是vs2008 如用vs2005 请注释using System.Linq;