Here is the C# code:

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;
 
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        DataSet ds = new DataSet();
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            // sample data
 
            ds.ReadXml(@"C:\mypath\customers.xml");
 
	   // initial customers list
	   // since the textbox is empty, it will show all the customers
            ShowCustomers(ds.Tables[0], textBox1.Text);
 
 
        }
 
        private void ShowCustomers(DataTable odt, string filter)
        {
	    // need to copy the exact schema for temperory datatable
            DataTable dt = odt.Clone(); 
            foreach (DataRow dr in odt.Select("Label like '" + filter + "%'"))
            {
                dt.ImportRow(dr);
 
            }
 
            listBox1.DataSource = dt;
            listBox1.DisplayMember = "Label";
            listBox1.ValueMember = "Value";
 
        }
 
        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            ShowCustomers(ds.Tables[0], textBox1.Text);
        }
    }
}
VN:F [1.1.6_502]
Rating: 0.0/5 (0 votes cast)
Share:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • DotNetKicks
  • LinkedIn
  • Live
  • MySpace
  • StumbleUpon
  • Technorati

Related posts:

  1. WinForms – Print using printDialog and printDocument
  2. Populate listbox in a thread in .net
  3. c# Listbox – change color of items
  4. Your first SQLite program on .NET
  5. Move a control with mouse on form