RadComboBox Text Property Binding MVVM

5 posts, 0 answers
  1. GVera
    GVera avatar
    10 posts
    Member since:
    Nov 2008

    Posted 18 May 2011 Link to this post

    Hi,

    I am having a hard time figuring out how to make the Text property of the RadComboBox bind to a string property in my View Model.  I have a combo box that is Editable so that user can search for anything that starts with the values typed on the text box.  I want to get that value in the view model, use it as part of a LINQ query (sarts with), and fill a collection source to display on a view.

    The problem:
    ------------------
    The string property on my view model "SearchText" is returning null (never gets the value entered by user).  Sample code is below:

            private List<SupplierMaster> foundSuppliers;
            public List<SupplierMaster> FoundSuppliers
            {
                get { return foundSuppliers; }
                set { if (foundSuppliers == value) return; foundSuppliers = value; OnPropertyChanged("FoundSuppliers"); }
            }
      
            private string searchText;
            public string SearchText
            {
                get { return searchText; }
                set { if (searchText == value) return; searchText = value; OnPropertyChanged("SearchText"); }
            }
      
            private void Search()
            {
                    FoundSuppliers = (from sm in SupplierMaster where sm.SupplierName.ToUpperInvariant().StartsWith(SearchText.ToUpperInvariant()) select sm).ToList();    //Here the SearchText property is always null **ISSUE**
                    FoundSuppliers = FoundSuppliers.OrderBy(n => n.SupplierName).ToList();            }
            }
      
      
    XAML:
      
                            <telerik:RadComboBox Height="23" Name="txtSearchBox" TabIndex="1" HorizontalAlignment="Left" 
                                             Width="246" IsEnabled="True" VerticalAlignment="Top" IsEditable="True" IsTextSearchEnabled="True"
                                             IsTextSearchCaseSensitive="True"  Text="{Binding SearchText}"
                                             TextSearchMode="StartsWithCaseSensitive" Margin="0,3" 
                                             ItemsSource="{Binding SupplierMaster}" 
                                             DisplayMemberPath="SupplierName" 
                                             SelectedValuePath="SupplierName"
                                             SelectedItem="{Binding SelectedSupplier}" EmptyText="Name starts with..."
                                             >
                                <telerik:RadComboBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <VirtualizingStackPanel />
                                </ItemsPanelTemplate>
                            </telerik:RadComboBox.ItemsPanel>
                        </telerik:RadComboBox>


    Please advice if this is possible or if I am missing something.

    Thanks,

    Gabe.
  2. GVera
    GVera avatar
    10 posts
    Member since:
    Nov 2008

    Posted 19 May 2011 Link to this post

    HELLO !!   Anyone available to answer my question???
  3. UI for WPF is Visual Studio 2017 Ready
  4. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 20 May 2011 Link to this post

    Hello Gabriel,

    You need to use TwoWay binding for the Text property of RadComboBox, as it binds OneWay by default.

    Greetings,
    Valeri Hristov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. John
    John avatar
    4 posts
    Member since:
    Jul 2011

    Posted 16 Sep 2011 Link to this post

    I'm having the same issue but I have TwoWay binding enabled. My property is never updated. I've tried with different UpdateSourceTriggers to no avail. Any help would be greatly appreciated.

    Regards,

    John

    <telerik:RadComboBox ItemsSource="{Binding FoundItems}"
                         EmptyText="{Binding EmptyText}"
                         TabIndex="0"
                         VerticalAlignment="Top"
                         Grid.Row="0"
                         IsReadOnly="False"
                         DisplayMemberPath="Name"
                         OpenDropDownOnFocus="True"
                         x:Name="searchCombo"
                         Height="30"
                         Text="{Binding SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                         IsEditable="True"
                         IsTextSearchCaseSensitive="False">
        <telerik:RadComboBox.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel />
            </ItemsPanelTemplate>
        </telerik:RadComboBox.ItemsPanel>
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="KeyDown">
                <i:InvokeCommandAction Command="{Binding BeginSearchCommand}"
                                       CommandParameter="{Binding ElementName=searchCombo, Path=SelectedItem}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </telerik:RadComboBox>
  6. John
    John avatar
    4 posts
    Member since:
    Jul 2011

    Posted 16 Sep 2011 Link to this post

    Nevermind. I'm an idiot. :)
Back to Top
UI for WPF is Visual Studio 2017 Ready