namespace WindowsApplication1
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.txt = new System.Windows.Forms.TextBox();
this.lst = new System.Windows.Forms.ListBox();
this.SuspendLayout();
this.txt.Location = new System.Drawing.Point(40, 21);
this.txt.Name = "txt";
this.txt.Size = new System.Drawing.Size(325, 20);
this.txt.TabIndex = 0;
this.txt.TextChanged += new System.EventHandler(this.txt_TextChanged);
this.txt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_KeyDown);
this.txt.Leave += new System.EventHandler(this.txt_Leave);
this.txt.Enter += new System.EventHandler(this.txt_Enter);
this.lst.FormattingEnabled = true;
this.lst.Location = new System.Drawing.Point(12, 37);
this.lst.Name = "lst";
this.lst.Size = new System.Drawing.Size(10, 4);
this.lst.TabIndex = 1;
this.lst.Visible = false;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(406, 309);
this.Controls.Add(this.lst);
this.Controls.Add(this.txt);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox txt;
private System.Windows.Forms.ListBox lst;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
DataTable tblList = new DataTable();
DataView dvList = null;
public Form1()
{
InitializeComponent();
}
private void txt_TextChanged(object sender, EventArgs e)
{
dvList.RowFilter = "Item Like '" + txt.Text + "%'";
}
private void txt_Enter(object sender, EventArgs e)
{
lst.Width = txt.Width;
lst.Height = 100;
lst.Top = txt.Top + txt.Height;
lst.Left = txt.Left;
if (!lst.Visible)
lst.Visible = true;
}
private void txt_Leave(object sender, EventArgs e)
{
if (lst.SelectedIndex != -1)
{
txt.Text = lst.Text;
}
else
{
txt.Text = "";
MessageBox.Show("Please select from list only !");
}
lst.Visible = false;
}
private void Form1_Load(object sender, EventArgs e)
{
tblList.Columns.Add("Item");
tblList.Rows.Add("ONE");
tblList.Rows.Add("TWO");
tblList.Rows.Add("THREE");
tblList.Rows.Add("FOUR");
tblList.Rows.Add("FIVE");
tblList.Rows.Add("SIX");
tblList.Rows.Add("SEVEN");
tblList.Rows.Add("EIGHT");
tblList.Rows.Add("NINE");
tblList.Rows.Add("TEN");
lst.DisplayMember = "Item";
lst.DataSource = tblList;
dvList = tblList.DefaultView;
}
private void txt_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyValue == 38)
{
lst.SelectedIndex = lst.SelectedIndex - 1;
}
else if (e.KeyValue == 40)
{
lst.SelectedIndex = lst.SelectedIndex + 1;
}
}
catch { }
}
}
}