How to create a "Search" textbox, with instant result show in listbox? Int value
Hi. I'm new to WPF (just 1 week before i have no ideas what it is)
I have a listbox, with data taken from a column (busId: int) in table "INFO" from SQL Server.
I want to create a Search textbox. When user enter some number, the listbox above will automatically filter the data to show only row that contain the number the user entered in textbox.
I've searched for this for days. Non of the solutions work.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Windows.Threading;
namespace Test2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private DataSet GetADOData()
{
DataSet dsSet = new DataSet();
string connectionString = @"Data Source=TRAN-D1652CEBAF\SQEXPRESS2;Initial Catalog=bus_test2;Integrated Security=True";
string sql="SELECT * FROM INFO";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command=new SqlCommand(sql, connection);
SqlDataAdapter adapter = new SqlDataAdapter();
connection.Open();
adapter.SelectCommand = command;
adapter.Fill(dsSet, "INFO");
}
return dsSet;
}
public MainWindow()
{
InitializeComponent();
BusInformation.DataContext = GetADOData();
}
Bookmarks