SelectedItem binding not working

2 posts, 1 answers
    HCT-CERT avatar
    22 posts
    Member since:
    Aug 2012

    Posted 23 Nov 2012 Link to this post


    I am using an AutoCompleteBox inside a RadDataForm template.The control ItemsSource is bound to an ObseravableCollcetion while the selected item is bound to a property on the window.

    <DataTemplate x:Key="MyTemplate">
                                <ColumnDefinition Width="200"/>
                                <ColumnDefinition Width="*"/>
                            <Label Content="Driver" Grid.Row="0"/>
                            <Label Content="Document Number" Grid.Row="1"/>
                            <Label Content="Issue Date" Grid.Row="2"/>
                            <Label Content="Expiry Date" Grid.Row="3"/>
                            <Label Content="Place of Issue" Grid.Row="4"/>
                            <Label Content="Document Type" Grid.Row="5"/>
                            <Label Content="Remarks" Grid.Row="6"/>
                            <telerik:RadAutoCompleteBox AutoCompleteMode="Suggest"
                                                 TextSearchPath="FullName"   ItemsSource="{Binding Drivers,ElementName=DriverDocumentView1}"    Name="RadAutoCompleteBox"  SearchTextChanged="RadAutoCompleteBox_SearchTextChanged" TextSearchMode="Contains" SelectionMode="Single"  DisplayMemberPath="Name" SelectedItem="{Binding SelectedDriver,ElementName=DriverDocumentView1}" Grid.Column="1" Grid.Row="0"/>
                            <TextBox Text="{Binding Document.DocumentNo}" Grid.Row="1" Grid.Column="1"/>
                            <DatePicker SelectedDate="{Binding IssueDate}"  Grid.Row="2" Grid.Column="1"/>
                            <DatePicker SelectedDate="{Binding ExpiryDate}"  Grid.Row="3" Grid.Column="1"/>
                            <ComboBox ItemsSource="{Binding PlacesOfIssue,ElementName=DriverDocumentView1}" DisplayMemberPath="Text" SelectedValuePath="ID" SelectedValue="{Binding Document.PlaceOfIssueID}" Grid.Column="1" Grid.Row="4"/>
                            <ComboBox ItemsSource="{Binding DocumentTypes,ElementName=DriverDocumentView1}" DisplayMemberPath="Name" SelectedValuePath="ID" SelectedValue="{Binding Document.DocumentTypeID}" Grid.Column="1" Grid.Row="5"/>
                            <TextBox Text="{Binding Remarks}" Grid.Row="6" Grid.Column="1"/>                      

    private Driver selectedDriver;
           public Driver SelectedDriver
               get { return selectedDriver; }
               set { selectedDriver = value; NotifyPropertyChanged("SelectedDriver"); }

    Now, the breakpoint I set in the 'set' part of the SelectedDriver property is not hit.I also find it to be null when sending the form data for saving:

    private void SaveBTN_Click(object sender, RoutedEventArgs e)
                if (RadDataForm.ValidateItem())
                    DriverDocument driverDocument = RadDataForm.CurrentItem.To<DriverDocument>();
                    driverDocument.Document.CreationDate = DateTime.Now;
                    driverDocument.Document.EntryByID = 178;
                    driverDocument.Driver = SelectedDriver;


  2. Answer
    Vladi avatar
    743 posts

    Posted 28 Nov 2012 Link to this post

    Hi Madani,

    We looked over the code snippets you sent to us and noticed that in the SelectedItem binding you haven't set the Mode to TwoWay. That is most probably the cause for the breakpoint in the set method of the SelectedDriver to not get hit.

    Setting the Mode in the binding should fix the issue you are having.

    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft R3 2016 release webinar banner
Back to Top