locked
How To restrict a user to select only ItemSource Values from AutoCompleteBox RRS feed

  • Question

  • Hi Team,
    I am unable to restric the end user to select the value which is not in ItemSource (or List)
    MY requirment is user has to select a value from autocomplete box only, if user selects or types which is not in the listautocomplete box text or selectedItem should become empty
    How could I accomplish this.
    my xaml is looks lik this

    xmlns:helpers="clr-namespace:CAST.Admin.Helpers"

    <UserControl.Resources>
    <helpers:FireCodeAutoCompleteLookupProvider x:Key="firecodeprovider"/>
    </UserControl.Resources>

    <c1:C1DataGrid AutoGenerateColumns="False" KeyDown="c1Adapter_KeyDown" LostFocus="activityCatalogDataGrid_LostFocus" ItemsSource="{Binding ElementName=c1Adapter, Path=Data}" x:Name="activityCatalogDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" toolkit:DockPanel.Dock="Top" CanUserFilter="True" CanUserEditRows="True" CanUserFreezeColumns="Left" CanUserGroup="True" CanUserReorderColumns="True" CanUserResizeColumns="True" CanUserSort="True" ShowGroupingPanel="True" CanUserAddRows="False" CanUserRemoveRows="False" FilterChanged="ActivityCatalogDataGridFilterChanged" SelectionChanged="activityCatalogDataGrid_SelectionChanged">
    <c1:C1DataGrid.Columns>
    <c1:DataGridTemplateColumn x:Name="firecodeAutocompletebox" Header="Fire Code" Name="FireCode">
    <c1:DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
    <TextBlock Name="txbFireCode" Text="{Binding Path=FireCode, Mode=TwoWay}" VerticalAlignment="Center" ></TextBlock>
    </DataTemplate>
    </c1:DataGridTemplateColumn.CellTemplate>
    <c1:DataGridTemplateColumn.CellEditingTemplate>
    <DataTemplate >

    <!--TextChanged="accfirecode1_TextChanged" -->
    <sdk:AutoCompleteBox x:Name="accfirecode1" LostFocus="accfirecode1_LostFocus"
    ValueMemberPath="ProductCode" FilterMode="StartsWith"
    SelectedItem="{Binding ProductCode, Mode=TwoWay}"
    Text="{Binding FireCode, Mode=TwoWay}"
    Width="Auto"
    ItemsSource="{Binding ProductCodes, Source={StaticResource firecodeprovider}}">
    <sdk:AutoCompleteBox.ItemTemplate>
    <DataTemplate>
    <StackPanel Orientation="Horizontal">
    <TextBlock Text="{Binding ProductCode, Mode=TwoWay}" Width="Auto"/>
    <TextBlock Text="|" Margin="05,0,05,0"/>
    <TextBlock Text="{Binding ProductCodeDesc, Mode=TwoWay}" VerticalAlignment="Center" Margin="10 0 0 0" />
    </StackPanel>
    </DataTemplate>
    </sdk:AutoCompleteBox.ItemTemplate>
    </sdk:AutoCompleteBox>
    </DataTemplate>
    </c1:DataGridTemplateColumn.CellEditingTemplate>
    </c1:DataGridTemplateColumn>
    </c1:C1DataGrid.Columns>
    </c1:C1DataGrid>

    ////////////////////// n Helper class
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using CAST.Admin.Web.Models;
    using CAST.Admin.Web.Services;
    using System.ServiceModel.DomainServices.Client;
    using System.Collections.Generic;
    using System.Linq.Expressions;
    namespace CAST.Admin.Helpers
    {
    public class FireCodeAutoCompleteLookupProvider:AutoCompleteBox
    {
    public static CASTDomainContext Context = new CASTDomainContext();
    public FireCodeAutoCompleteLookupProvider()
    {
    try
    {
    Context.Load(Context.GetProductCodesQuery(), LoadBehavior.RefreshCurrent, false);
    }
    catch (InvalidOperationException)
    { }
    }
    public EntitySet<CAST.Admin.Web.Models.ProductCodes> ProductCodes
    {
    get
    {
    Context.Load(Context.GetProductCodesQuery(), LoadBehavior.RefreshCurrent, false);
    return Context.ProductCodes;
    }
    }
    }
    }
    How can i do this , i tried with few event but not got result. Here we are using componentOne controls
    please help me onthis as soon as possible.


    Srilatha

    Thursday, November 27, 2014 6:28 AM

All replies