This is a migrated thread and some comments may be shown as answers.

Setting the searchText

9 Answers 318 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
danparker276
Top achievements
Rank 2
danparker276 asked on 02 Nov 2012, 11:08 PM
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?

9 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 07 Nov 2012, 02:57 PM
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.

0
danparker276
Top achievements
Rank 2
answered on 08 Nov 2012, 12:57 AM
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:

0
Vladi
Telerik team
answered on 08 Nov 2012, 01:24 PM
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.

0
danparker276
Top achievements
Rank 2
answered on 08 Nov 2012, 06:11 PM
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>
0
Vladi
Telerik team
answered on 09 Nov 2012, 08:37 AM
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.

0
lnu
Top achievements
Rank 1
answered on 22 Nov 2012, 03:52 PM
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
0
Vladi
Telerik team
answered on 26 Nov 2012, 11:14 AM
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.

0
Omar
Top achievements
Rank 1
answered on 21 Apr 2014, 05:42 PM
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.
0
Kalin
Telerik team
answered on 22 Apr 2014, 08:55 AM
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.

 
Tags
AutoCompleteBox
Asked by
danparker276
Top achievements
Rank 2
Answers by
Vladi
Telerik team
danparker276
Top achievements
Rank 2
lnu
Top achievements
Rank 1
Omar
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or