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

RadAutoCompleteBox in DataGridTemplateColumn

8 Answers 287 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 23 Nov 2012, 09:31 AM
Hi!

There seems to be a bug in RadAutoCompleteBox displayed in DataGridTemplateColumns. While editing the DataGrid row the Texts of SelectedItems aren't visible but on lost focus they are.

namespace WpfApplication.ViewModels
{
    public class ListViewModel
    {
        public ListViewModel()
        {
            this.ViewModels = new ObservableCollection<ViewModel>() { new ViewModel() };
        }
         
        public ObservableCollection<ViewModel> ViewModels { get; set; }
         
    }
 
    public class ViewModel
    {
        public ObservableCollection<Country> AvailableCountries { get; set; }
        public ObservableCollection<string> SelectedCountries { get; set; }
  
        public ViewModel()
        {
            this.AvailableCountries = new ObservableCollection<Country>()
            {
                new Country() { Name = "Australia" , Capital = "Canberra" },
                new Country() { Name = "Bulgaria", Capital = "Sofia" },
                new Country() { Name = "Canada" , Capital = "Ottawa" },
                new Country() { Name = "Denmark" , Capital = "Copenhagen" },
                new Country() { Name = "France" , Capital = "Paris" },
                new Country() { Name = "Germany" , Capital = "Berlin" },
                new Country() { Name = "India" , Capital = "New Delhi" },
                new Country() { Name = "Italy" , Capital = "Rome" },
                new Country() { Name = "Norway" , Capital = "Oslo" },
                new Country() { Name = "Russia" , Capital = "Moscow" },
                new Country() { Name = "Spain " , Capital = "Madrid" },
                new Country() { Name = "United Kingdom" , Capital = "London" },
                new Country() { Name = "United States" , Capital = "Washington, D.C." },
            };
  
            this.SelectedCountries = new ObservableCollection<string>();
  
        }
    }
}

<Window x:Class="WpfApplication.MainWindow"
        xmlns:local="clr-namespace:WpfApplication.ViewModels"
        Title="MainWindow"
        Width="525"
        Height="350">
    <Window.Resources>
        <local:ListViewModel x:Key="ListViewModel" />
    </Window.Resources>
    <Grid>
        <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding ViewModels, Source={StaticResource ListViewModel}}">
            <DataGrid.Columns>
                <DataGridTemplateColumn Width="*">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:RadAutoCompleteBox DisplayMemberPath="Name"
                                                        ItemsSource="{Binding AvailableCountries}"
                                                        SelectedItems="{Binding SelectedCountries}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>

Could you check that please?

8 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 28 Nov 2012, 04:03 PM
Hi Marco,

We were able to reproduce the described behavior and we are currently investigating what could be the cause of it.

When we have more information on the case we will write in this thread.

Kind regards,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Accepted
Vladi
Telerik team
answered on 30 Nov 2012, 07:49 AM
Hello Marco,

We debugged the issue and found out what is the cause of the issue. We will do our best to have a permanent fix as soon as possible in our next releases of RadControls.

In the mean while you can use this workaround:
  1. Using Implicit Styles merge the needed dictionaries for the AutoCompleteBox control (System.Windows.xaml, Telerik.Windows.Controls.xaml and Telerik.Windows.Controls.Input.xaml) in the App.xaml.
  2. Customize the RadAutoCompleteBoxItem Style, change its Foreground to black and place it in the App.xaml.

The next code snippet shows how to merge the dictionaries and to create that Style in the App.xaml:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/System.Windows.xaml"/>
            <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.xaml"/>
            <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.Input.xaml"/>
        </ResourceDictionary.MergedDictionaries>
        <Style TargetType="telerik:RadAutoCompleteBoxItem" BasedOn="{StaticResource RadAutoCompleteBoxItemStyle}">
            <Setter Property="Foreground" Value="Black" />
        </Style>
    </ResourceDictionary>
</Application.Resources>

Hope this is helpful.
 
Regards,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Marco
Top achievements
Rank 1
answered on 29 Dec 2012, 06:33 PM
Thanks Vladi!

That works for me.

Greetings,
Marco
0
Alex R.
Top achievements
Rank 1
answered on 26 May 2016, 04:36 PM

Using version 2016.2.503.45 I am experiencing the opposite as the user in the original post.  Any ideas?

 

<UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ResourceDictionary.xaml"/>
                <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/System.Windows.xaml"/>
                <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.xaml"/>
                <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Input.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <Style TargetType="telerik:RadAutoCompleteBoxItem" BasedOn="{StaticResource RadAutoCompleteBoxItemStyle}">
                <Setter Property="Foreground" Value="Black" />
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>

 

<telerik:GridViewDataColumn Name="cDocumentTagColumn" Width="300"  Header="Document Tags">
    <telerik:GridViewDataColumn.CellEditTemplate>
        <DataTemplate>
            <telerik:RadAutoCompleteBox ItemsSource="{Binding AvailableDocumentTags}"
                                        SelectedItems="{Binding DocumentTags}"
                                        DisplayMemberPath="Description"
                                        WatermarkContent="Enter Document Tags"
                                        SelectionMode="Multiple"
                                        Foreground="Black"/>
        </DataTemplate>
    </telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>

               

0
Yana
Telerik team
answered on 31 May 2016, 08:31 AM
Hello Alex,

As the AutoCompleteBox inside the CellEditTemplate is in multiple selection mode, you will need to add also a CellTemplate with ItemsControl inside it which could show multiple items. Here is a quick example with a ListBox:

<telerik:GridViewDataColumn.CellTemplate>
    <DataTemplate>
        <ListBox ItemsSource="{Binding SelectedCountries}" DisplayMemberPath="Name" Width="200">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>
    </DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>

I have also attached a sample project to demonstrate the approach.

Hope this would be helpful.

Regards,
Yana
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Alex R.
Top achievements
Rank 1
answered on 30 Jun 2016, 02:25 PM

My apologies for the delayed response.  Your example worked well, my problem was caused by using CellEditTemplate and not CellTemplate.

 

I do have a new issue.  If I click on my autocomplete box it works great, however if I should tab from the column before it the cell the autocomplete box lives in is active that the autocomplete box is hidden.  How do I get the autocomplete box focus when I tab?

0
Nasko
Telerik team
answered on 04 Jul 2016, 11:12 AM
Hi Alex,

What we could suggest you as one possible approach to achieve the desired behavior is to handle the PreviewKeyUp event of the GridView. Inside it to check if Tab key is pressed and if so to call the BeginEdit method of the GridViewCell:
private void RadGridView_PreviewKeyUp(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Tab)
    {
        var gridViewCell = e.OriginalSource as GridViewCell;
        if (gridViewCell != null)
        {
            gridViewCell.BeginEdit();
        }
    }
}

Please, give it a try and let us know if it worked for you.

Hope this helps.

Regards,
Nasko
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
qui
Top achievements
Rank 1
answered on 19 Sep 2017, 02:34 AM
thanks @Vladi, it is helpful
Tags
AutoCompleteBox
Asked by
Marco
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Marco
Top achievements
Rank 1
Alex R.
Top achievements
Rank 1
Yana
Telerik team
Nasko
Telerik team
qui
Top achievements
Rank 1
Share this question
or