Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

i have create a custom cotrol textbox and i want to display the listview on the text change event of the textbox .
the problem is that my program is build sucessfuly with out any error and warning . but it does not display the listview on the text change event pls give me the solution for that ...
i have place my code of custom control text box below..
thanks..
waiting for reply


C#
public partial class Text_Box : TextBox
  {
      ListView listView1 = new System.Windows.Forms.ListView();
      public Text_Box()
      {
          InitializeComponent();
      }
      protected override void OnPaint(PaintEventArgs pe)
      {
          base.OnPaint(pe);
      }
      private void Text_Box_Enter(object sender, EventArgs e)
      {
          this.BackColor = Color.LightYellow;
          this.ForeColor = Color.Blue;
      }
      private void Text_Box_Leave(object sender, EventArgs e)
      {
          this.BackColor = Color.White;
          this.ForeColor = Color.Black ;
      }
      public void InitListView(ListView lstviw)
      {
          // this1.BorderStyle = BorderStyle.FixedSingle;
          lstviw.Dock = DockStyle.None;
          lstviw.Items.Clear();
          lstviw.HeaderStyle = ColumnHeaderStyle.Nonclickable;
          lstviw.FullRowSelect = true;
          lstviw.GridLines = true;
          lstviw.MultiSelect = false;
          lstviw.AutoArrange = true;
          lstviw.Size = new System.Drawing.Size(292, 220);
          lstviw.Location = new Point(this.Location.X, this.Location.Y + 20);
          lstviw.View = View.Details;
          ColumnHeader[] columns = { new ColumnHeader(), new ColumnHeader() }; // this is what I'd like to shorten
          columns[0].Text = "Name";
          columns[0].Width = 200;
          columns[1].Text = "City";
          columns[1].Width = 100;
          lstviw.Columns.AddRange(columns);
          lstviw.Show();
          //lstviw.Visible = true;
          //this.Controls.Add(lstviw);
         // listView1.KeyDown += new KeyEventHandler(listView1_KeyDown);
      }
      private void Text_Box_TextChanged(object sender, EventArgs e)
      {
          InitListView(listView1);
      }
  }
Posted
Updated 6-Oct-10 20:40pm
v2
Comments
Rhuros 7-Oct-10 8:08am    
I've tried your code (admittedly I've called your InitListView() from a TextChanged Event on a standard TextBox) and it seems to work as expected. So my question is how are you attaching your TextChanged event handler to your text box? Have you done it as part of the properties tab for the control? Is it inside InitializeComponent?
Sagar Khairnar 55 7-Oct-10 8:16am    
hi,
now i can display the listview on the form binded to the textbox.. i have just added few line to display that...
in text change event i did... the following code

try
{
fillListView();
listView1.Visible = true;
foundItem = listView1.FindItemWithText(this.Text);
int i = listView1.FindItemWithText(this.Text).Index;
if (foundItem != null)
{
if (listView1.Items.Contains(foundItem))
{
listView1.Items[i].Selected = true;
listView1.Focus();
listView1.Parent = this;
listView1.BringToFront();
this.Parent.Controls.Add(listView1);
}
else
listView1.Hide();
}
}
thus my multi column combo box is ready to use..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900