我在app_code里面寫了一個添加listview的方法,當我打開a窗體的時候調用這個方法添加這個listview,現在
復雜的事當我點擊這個listview想返回點擊的值給窗體上的一個textbox???
如何做~

解决方案 »

  1.   

    给自定义控件一个public属性,处理后给这个属性赋值,如:控件:A
    {
    public string Result{
    get{
    return _result;
    }
    }
    }窗体:B
    {
    Response.Write(控件.Result);
    }
      

  2.   

         以下代碼是放在App_Code的一個.cs文件里面  public static void DownListView(Form fr,int Px, int Py,int width,int height,string headname,string tablename,string fieldname,string val)
           {
               ListView showvalue1 = new ListView();
               showvalue1.FullRowSelect = true;
               showvalue1.GridLines = true;
               showvalue1.Location = new System.Drawing.Point(Px, Py);
               showvalue1.Size = new System.Drawing.Size(width, height);
                showvalue1.TabIndex = 10;
                showvalue1.UseCompatibleStateImageBehavior = false;
                showvalue1.View = System.Windows.Forms.View.Details;
                showvalue1.Visible = true;
                showvalue1.Columns.Add(headname,width);
                showvalue1.View = View.Details;
                SendData_ListViewByFiled(showvalue1, tablename, fieldname, val);
                fr.Controls.Add(showvalue1);
                fr.Controls.SetChildIndex(showvalue1, 0);
               showvalue1.Click+=new EventHandler(showvalue1_Click);
           }
           public static void showvalue1_Click(object sender, EventArgs e)
           {
               //if (((ListView)sender).SelectedItems.Count > 0)
               //{
                   Temp_Value._YWY = ((ListView)sender).SelectedItems[0].Text.ToString();
                    //MessageBox.Show(((ListView)sender).SelectedItems[0].Text.ToString());
                    ((ListView)sender).Visible = false;
               //}
           }
    我在A窗體的一個textbox1里面的gotfocus里面調用這個方法,然后顯示相關數據,當用戶點擊的時候,返回點擊
    的值給A窗體的TEXTBOX1,其實目的就是讓用戶輸入第一個字母就只要點擊listview下面對應的數據,節省時間