SIGN UP MEMBER LOGIN:    
ARTICLE

AutoCompleteTextBox in WPF

Posted by Rahul Kumar Saxena Articles | WPF April 12, 2010
In this article I am going to show about AutoCompleteTextBox in WPF.
Reader Level:
 

In this article I am going to show AutoCompleteTextBox in WPF. AutoCompleteTextBox mean when we type something to search in a textbox to get a small list of valid search results that match the search string entered so far. In this article I am using Linq to Sql also. I have saved my DataBase inside DATA folder. To run the application just add this database and change connection string from setting inside properties folder.

See in this image.

WTImg2.JPG 

Image 1.

Just change here DataSource according to you server name.

This is my DataTable from which records are coming.

WTImg1.JPG 

Image 2.

This is my XAML code.

<Window x:Class="AutoCompleteTextBoxInWPF.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="MainWindow" Height="250" Width="350">

    <Grid Background="AliceBlue">

        <Grid.RowDefinitions>

            <RowDefinition Height="40" />

            <RowDefinition Height="203" />

        </Grid.RowDefinitions>

        <TextBlock Text="Search :" HorizontalAlignment="Left"

                   VerticalAlignment="Bottom" Width="70" Height="15.96" Margin="31,0,0,4" />

        <TextBox HorizontalAlignment="Right" VerticalAlignment="Bottom"

                 Height="25" Width="160" Margin="0,0,10,0" x:Name="txtName" TextWrapping="NoWrap" SelectionChanged="txtName_SelectionChanged" />

        <ListBox x:Name="listName" SelectionChanged="listName_SelectionChanged"

            Background="LightCyan" Grid.Row="1" Visibility="Collapsed"

                 HorizontalAlignment="Right" VerticalAlignment="Top" Width="160" Margin="0,0,10,0"/>

    </Grid>

</Window>

 

When we run the application and want to search name which start with "R".

WTImg3.JPG 

Image 3.

If we type character "E", then the textbox will show all names starting with this character.

WTImg4.JPG 

Image 4.

share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor