AutocompleteBox Binding problems

2 posts, 0 answers
  1. Jose
    Jose avatar
    1 posts
    Member since:
    Mar 2016

    Posted 05 Mar Link to this post

     

     

    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 .
  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 08 Mar Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top