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

AutocompleteBox Binding problems

1 Answer 48 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Jose
Top achievements
Rank 1
Jose asked on 05 Mar 2016, 03:35 PM

 

 

I'm having probelas with the binding of radautocompletebox in raddatagridview , in this example the GridViewComboBoxColumn the ItemsSource works correctly but the ItemsSource RadAutoCompleteBox does not work.

Can anyone help.

 

*** VIEW

using ViewModels;
using System.Windows;

namespace Windows
{
     public partial class frmTestes : Window
    {
        public frmTestes()
        {
            InitializeComponent();
            this.DataContext = new vmTeste(myConnection, System.DateTime.Now);
        }
    }
}

 

**** XAML

<Window x:Name="window"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Windows"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"

        x:Class="Windows.frmTestes" mc:Ignorable="d" Title="frmTestes" >
    <Grid>
        <TabControl x:Name="tabControl">
            <TabItem Header="TabItem1">
                <telerik:RadGridView CanUserDeleteRows="False"   
                                     AlternationCount="2"
                                     BorderThickness="0"
                                     ShowGroupPanel="True"
                                     AlternateRowBackground="#FFF0F0F0"
                                     AutoGenerateColumns="False"
                                     RowDetailsVisibilityMode="Collapsed"
                                     RowIndicatorVisibility="Collapsed"
                                     ItemsSource="{Binding linhas}">

                    <telerik:RadGridView.Columns>
                        <telerik:GridViewComboBoxColumn Header="Código" MinWidth="110" IsComboBoxEditable="True"  
                                                        DataMemberBinding="{Binding artigo}"
                                                        SelectedValueMemberPath="artigo"
                                                        DisplayMemberPath="artigo"
                                                        telerik:TextSearch.TextPath="artigo"
                                                        ItemsSource="{Binding DataContext.artigos, ElementName=window}">
                        </telerik:GridViewComboBoxColumn>

                        <telerik:GridViewDataColumn UniqueName="designacao" Header="Designação" Width="*" DataMemberBinding="{Binding desig1}">
                            <telerik:GridViewDataColumn.CellEditTemplate>
                                <DataTemplate>
                                    <telerik:RadAutoCompleteBox SelectedItem="{Binding artigos.desig1, Mode=TwoWay}"
                                                                ItemsSource="{Binding DataContext.artigos, ElementName=window}"
                                                                SelectionMode="Single" 
                                                                TextSearchMode="Contains"
                                                                DisplayMemberPath="desig1"
                                                                SearchText="{Binding desig1}"/>
                                </DataTemplate>
                            </telerik:GridViewDataColumn.CellEditTemplate>
                        </telerik:GridViewDataColumn>
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>
            </TabItem>
            <TabItem Header="TabItem2"/>
           </TabControl>
    </Grid>
</Window>

 

**** VIEWMODEL

using System;
using System.Collections.ObjectModel;
using System.Data.SqlClient;

namespace ViewModels
{
    public class vmTeste : BaseViewModel
    {
        public vmTeste(SqlConnection _connection, DateTime _datatrabalho)
        {
            linhas_ = getLinhasFromSQL(_connection, _datatrabalho);
            artigos_ = getArtigosFromSQL(_connection, _datatrabalho);
        }

        private ObservableCollection<Linha> linhas_;
        public ObservableCollection<Linha> linhas
        {
            get
            {
                return this.linhas_;
            }
            set
            {
                linhas_ = value;
            }
        }
   
        private ObservableCollection<Artigo> artigos_;
        public ObservableCollection<Artigo> artigos
        {
            get
            {
                return this.artigos_;
            }
        }
    }
}

Thanks
I'm having probelas with the binding of radautocompletebox in raddatagridview , in this example the GridViewComboBoxColumn the ItemsSource works correctly but the ItemsSource RadAutoCompleteBox does not work. Can anyone help .
I'm having probelas with the binding of radautocompletebox in raddatagridview , in this example the GridViewComboBoxColumn the ItemsSource works correctly but the ItemsSource RadAutoCompleteBox does not work. Can anyone help .

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 08 Mar 2016, 02:40 PM
Hello Jose,

Please try binding the AutoCompleteBox ItemsSource like this:

<telerik:RadAutoCompleteBox
    SelectedItem="{Binding artigos.desig1, Mode=TwoWay}"
    ItemsSource="{Binding DataContext.artigos, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"
    SelectionMode="Single"
    TextSearchMode="Contains"
    DisplayMemberPath="desig1"
    SearchText="{Binding desig1}"/>

Let us know whether it's ok now.

Regards,
Yana
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
AutoCompleteBox
Asked by
Jose
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or