SelectedItem binding not working

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

    Posted 23 Nov 2012 Link to this post

    Hi,

    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">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="200"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <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"/>                      
                        </Grid>
                            
     
     
                    </DataTemplate>

    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;
                    RadDataForm.SubmitChanges();
     
                }
            }


    Thanks

    Madani
  2. Answer
    Vladi
    Admin
    Vladi avatar
    744 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.

    Regards,
    Vladi
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top