问题:
利用三个控件Textbox1 botton1 listview1 实现在文本框里输入相应内容,按botton键,在listview中显示出来,希望能有必要的代码,谢谢~~

解决方案 »

  1.   

    想写,但没listview,你是05的?
    UP
      

  2.   


    listView1.Items.Add("List item text", 3);
      

  3.   

    private void button1_Click(object sender, System.EventArgs e)
            {
                this.listView1.Items.Add(this.textBox1.Text);
            }
      

  4.   

    listView1.Items.Add("List item text", 3);这个不对吧??
      

  5.   

    private void button1_Click(object sender, System.EventArgs e)
    {
    listView1.Items.Add(textBox1.Text);
    }
      

  6.   

    在botton1单击事件中:listview1.items.add(textbox1.text)
      

  7.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace Test
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.ListView listView1;
    private System.Windows.Forms.ColumnHeader ColunmHeader1;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (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.listView1 = new System.Windows.Forms.ListView();
    this.ColunmHeader1 = new System.Windows.Forms.ColumnHeader();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(24, 96);
    this.button1.Name = "button1";
    this.button1.TabIndex = 1;
    this.button1.Text = "button1";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // textBox1
    // 
    this.textBox1.Location = new System.Drawing.Point(16, 12);
    this.textBox1.Name = "textBox1";
    this.textBox1.TabIndex = 2;
    this.textBox1.Text = "textBox1";
    // 
    // listView1
    // 
    this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
    this.ColunmHeader1});
    this.listView1.GridLines = true;
    this.listView1.Location = new System.Drawing.Point(130, 12);
    this.listView1.Name = "listView1";
    this.listView1.TabIndex = 3;
    this.listView1.View = System.Windows.Forms.View.Details;
    // 
    // ColunmHeader1
    // 
    this.ColunmHeader1.Text = "文本框内容";
    this.ColunmHeader1.Width = 98;
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Controls.Add(this.listView1);
    this.Controls.Add(this.textBox1);
    this.Controls.Add(this.button1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void button1_Click(object sender, System.EventArgs e)
    {
    if (textBox1.Text!="")
    {
    string[] subItem={textBox1.Text};
    //lstUserInfo.Items.Insert(itemNumber,new ListViewItem(subItem6));
    listView1.Items.Add(new ListViewItem(subItem));
    }
    }
    }
    }
      

  8.   

    string[] subItem={textBox1.Text};
    listView1.Items.Add(new ListViewItem(subItem));
      

  9.   

    private void btSearch_Click(object sender, EventArgs e)
            {
                if (this.tbSearch.Text == "") return;
                this.cbbSearch.Items.Clear();
                odCmd.CommandText = string.Format("SELECT SightName FROM {0} WHERE Re Like '%{1}%'", this.tbTable.Text, this.tbSearch.Text.Trim());
                OleDbDataReader oddr = odCmd.ExecuteReader();
                while (oddr.Read())
                {
                    string sType = oddr.GetString(0);
                    
                    this.cbbSearch.Items.Add(sType);
                }
                oddr.Close();
                if (this.cbbSearch.Items.Count > 0) this.cbbSearch.SelectedIndex = 0;
            }        private void cbbSearch_SelectedIndexChanged(object sender, EventArgs e)        {
                odCmd.CommandText = string.Format("SELECT * FROM {0} WHERE Re LIKE '%{1}%' AND SightName = '{2}'", this.tbTable.Text, this.tbSearch.Text.Trim(), this.cbbSearch.SelectedItem.ToString());
                this.GetReaderContents();
            }
    我是要把数据库里的同一属性的数据显示在listview中,我模仿上面的comboBox例子,可是写出来的总出错啊,哪们大虾帮帮我啊,问题解决就结帖,不想占用大家太多时间