Setting the searchText

10 posts, 0 answers
  1. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 02 Nov 2012 Link to this post

    First thank you so much for this control.  It is very useful.

    I want to set a value in the search box, but I get a null error when I try

    myAutoCompleteBox.SearchText = "TEST1";

    How can I set what's in the textbox?  Value or Text isn't.  I suppose I could write a linq query and do selecteditem, but what if I just want to put text into that textbox that doesn't match anything in the list.

    Also, I'm guessing there is nothing built in to highlight the matched text.  I can probably do this with templates though.

    I'm also guessing that the virtualization is automatic and default.  I don't have to set this like I do in the combobox right?
  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 07 Nov 2012 Link to this post

    Hi Dan,

    Straight to your questions.

    • We tried to reproduce the issue with the SearchText property but with no success. Are you sure you are not setting the property before the control is loaded?
    • In RadAutoCompleteBox there isn't a best matched item so there isn't a built-in feature for highlighting an item based in the filtering.
    • The virtualization mechanism in the control is turned on by default.

    If you have any other questions do not hesitate to contact us again.

    Regards,
    Vladi
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 07 Nov 2012 Link to this post

    Actually I'm getting an error.  I can reproduce it in a new project:

    <Window x:Class="TestAutoCompleteBox.MainWindow"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                    Title="MainWindow" Height="350" Width="525">
            <Grid>
                    <telerik:RadAutoCompleteBox  Name="rac1" Width="120" Height="25" />
            </Grid>
    </Window>

    Then
    public MainWindow()
    {
        InitializeComponent();
        List<String> ls = new List<string>() { "hello","abc", "123" };
        rac1.ItemsSource = ls;
        rac1.SearchText = "h";
    }


    If I run this I get an error:

    System.Reflection.TargetInvocationException was unhandled
      HResult=-2146232828
      Message=Exception has been thrown by the target of an invocation.
      Source=mscorlib
      StackTrace:
           at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
           at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
           at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
           at System.Activator.CreateInstance(Type type, Boolean nonPublic)
           at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
           at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
           at System.Activator.CreateInstance(Type type, Object[] args)
           at System.Xaml.Schema.SafeReflectionInvoker.CreateInstanceCritical(Type type, Object[] arguments)
           at System.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object[] arguments)
           at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType, Object[] args)
           at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)
           at System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
           at System.Xaml.XamlObjectWriter.WriteStartMember(XamlMember property)
           at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
           at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
           at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
           at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
           at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
           at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
           at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
           at System.Windows.Application.DoStartup()
           at System.Windows.Application.<.ctor>b__1(Object unused)
           at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.DispatcherOperation.InvokeImpl()
           at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Windows.Threading.DispatcherOperation.Invoke()
           at System.Windows.Threading.Dispatcher.ProcessQueue()
           at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
           at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
           at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
           at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
           at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
           at System.Windows.Threading.Dispatcher.Run()
           at System.Windows.Application.RunDispatcher(Object ignore)
           at System.Windows.Application.RunInternal(Window window)
           at System.Windows.Application.Run(Window window)
           at System.Windows.Application.Run()
           at TestAutoCompleteBox.App.Main() in e:\TestVS\TestAutoCompleteBox\TestAutoCompleteBox\obj\x86\Debug\App.g.cs:line 0
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.NullReferenceException
           HResult=-2147467261
           Message=Object reference not set to an instance of an object.
           Source=Telerik.Windows.Controls.Input
           StackTrace:
                at Telerik.Windows.Controls.RadAutoCompleteBox.OnSearchTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) in c:\TB\105\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\RadAutoCompleteBox.cs:line 946
                at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
                at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
                at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
                at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
                at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
                at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
                at Telerik.Windows.Controls.RadAutoCompleteBox.set_SearchText(String value) in c:\TB\105\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\RadAutoCompleteBox.cs:line 261
                at TestAutoCompleteBox.MainWindow..ctor() in e:\TestVS\TestAutoCompleteBox\TestAutoCompleteBox\MainWindow.xaml.cs:line 28
           InnerException:

  5. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 08 Nov 2012 Link to this post

    Hello Dan,

    If you set the SearchText property just after the InitializeComponent() method the AutoCompleteBox control hasn't been loaded yet. Before setting the SearchText property you should make sure that the RadAutoCompleteBox is loaded.

    A simple solution is to set the property in the Loaded event of the control.
    The next code snippet shows how to achieve that:
    In the xaml:
    <telerik:RadAutoCompleteBox Loaded="autoComleteBox_Loaded_1"/>

    and in the code behind:
    private void autoComleteBox_Loaded_1(object sender, RoutedEventArgs e)
    {
        this.autoComleteBox.SearchText = "Text";
    }

    Hope this is helpful.

    Regards,
    Vladi
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 08 Nov 2012 Link to this post

    Ok, that now works in my simple example, but it fails when I put it in a RadTabControl.  The code below fails for me. If I do:
            void rac1_Loaded(object sender, RoutedEventArgs e)
            {
                rac1.SearchText = "h";
            }


    <Window x:Class="TestAutoCompleteBox.MainWindow"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                    Title="MainWindow" Height="350" Width="525">
            <Grid>
            <telerik:RadTabControl VerticalAlignment="Center" Padding="5" Name="rtcClMtTabs"
                                    Margin="0 3 0 0" Height="530" Width="800" IsContentPreserved="False"
                                    DataContext="{Binding}" HeaderBackground="Transparent" BorderThickness="2">
                <telerik:RadTabItem DropDownContent="General0" IsSelected="True">
                    <telerik:RadAutoCompleteBox  Name="rac1" Loaded="rac1_Loaded" Width="120" Height="25" />
                </telerik:RadTabItem>
            </telerik:RadTabControl>
        </Grid>
    </Window>
  7. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 09 Nov 2012 Link to this post

    Hi Dan,

    After further testing the issue we found out that there is a bug in the control concerning SearchText property. We will do our best to have the issue fixed as soon as possible, it will most probably be available in the next internals builds.

    I updated your Telerik points for bring this to our attention.

    Greetings,
    Vladi
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. lnu
    lnu avatar
    19 posts
    Member since:
    Aug 2012

    Posted 22 Nov 2012 Link to this post

    I think I'm facing the same bug. Except in my case everything is set by binding.
    When can we expect a fix?

    Thank you
  9. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 26 Nov 2012 Link to this post

    Hi Laurent,

    This issue has already been fixed and it should be available in the Q3 2012 SP1 release of RadControls which will be released in the next few days.

    All the best,
    Vladi
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. Omar
    Omar avatar
    2 posts
    Member since:
    Aug 2013

    Posted 21 Apr 2014 Link to this post

    Hello,

    I'm working with the Q1 2014 controls and while trying to pre-set the SearchText property on the ViewModel associated with the AutoCompleteBox I'm seeing that there is a call to get the value which returns my initialized value but then after that there is a call setting it to an empty string. So the control is basically clearing my property on load, I tried this with a simple textbox and it works correctly.
  11. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 22 Apr 2014 Link to this post

    Hi Omar,

    We aware of the explained issue and it has already been fixed. The fix is available with the latest internal build from yesterday, so what I can suggest you is to give it a try.

    Hope this helps.

    Regards,
    Kalin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready