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

SelectedItem binding not working

1 Answer 575 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
HCT-CERT
Top achievements
Rank 1
HCT-CERT asked on 23 Nov 2012, 12:48 PM
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

1 Answer, 1 is accepted

Sort by
0
Accepted
Vladi
Telerik team
answered on 28 Nov 2012, 09:44 AM
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.

Tags
AutoCompleteBox
Asked by
HCT-CERT
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Share this question
or