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

RadComboBox Text Property Binding MVVM

4 Answers 1515 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
GVera
Top achievements
Rank 1
GVera asked on 18 May 2011, 01:42 PM
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.

4 Answers, 1 is accepted

Sort by
0
GVera
Top achievements
Rank 1
answered on 19 May 2011, 04:52 PM
HELLO !!   Anyone available to answer my question???
0
Valeri Hristov
Telerik team
answered on 20 May 2011, 10:23 AM
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
0
John
Top achievements
Rank 1
answered on 16 Sep 2011, 08:54 PM
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>
0
John
Top achievements
Rank 1
answered on 16 Sep 2011, 09:36 PM
Nevermind. I'm an idiot. :)
Tags
ComboBox
Asked by
GVera
Top achievements
Rank 1
Answers by
GVera
Top achievements
Rank 1
Valeri Hristov
Telerik team
John
Top achievements
Rank 1
Share this question
or