Dear all....,
Here i have an textbox and listbox.in runtime some datastored in listbox which is invisible.when i entered text in text that time listbox apper wiht text contains with respest to text in textbox.Up to now i got correct.Now my prob is after enter text in textbox list box apper and selest items in listbox through up and down arrows,after enter then the selected text in listbox placed into that textbox.For this my test program u find in attachment.Please help me to solve my proble...
Thanks in advance.
Regards,
VishnuVardhan D.
Loading
Datta KharadPosted Dec 14, 2011, 1:06 AM
Your problem has solved, see the following code or find in attachment.
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;
using System.Runtime.InteropServices;
namespace testcombo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
}
else
{
return;
}
listBox2.Items.Clear();
for (int i = 0; i < listBox1.Items.Count; i++)
{
if (listBox1.Items[i].ToString().Contains(textBox1.Text))
{
listBox2.Visible = true;
if (!listBox2.Items.Contains(textBox1.Text))
{
listBox2.Items.Add(listBox1.Items[i]);
}
}
}
}
private const int WM_VSCROLL = 0x115;
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam);
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Up:
if (listBox2.Items.Count > 1)
{
if (listBox2.SelectedIndex > 0)
listBox2.SelectedIndex = listBox2.SelectedIndex - 1;
}
else if (listBox2.Items.Count == 1)
{
listBox2.SelectedIndex = 0;
}
break;
case Keys.Down:
if (listBox2.Items.Count > 1)
{
if (listBox2.SelectedIndex != listBox2.Items.Count - 1)
listBox2.SelectedIndex = listBox2.SelectedIndex + 1;
}
else if (listBox2.Items.Count == 1)
{
listBox2.SelectedIndex = 0;
}
break;
case Keys.Enter:
if (listBox2.SelectedIndex != -1)
{
textBox1.Text = listBox2.Text;
listBox2.Visible = false;
}
break;
}
}
}
}
Datta KharadPosted Dec 14, 2011, 3:02 AM
vishnuvardhan diyyalaPosted Dec 14, 2011, 1:28 AM