GridView captured user input first in Q2 2011

7 posts, 0 answers
  1. Xinfeng
    Xinfeng avatar
    15 posts
    Member since:
    Jul 2011

    Posted 27 Jul 2011 Link to this post

    Hi,

    We created a custom toolbar implemented as RadGridViewToolbar : Behavior<RadGridView>. Please see the following code snippet.

     public class RadGridViewToolbar : Behavior<RadGridView>
     {       
            protected override void OnAttached()
            {
                base.OnAttached();          
                AssociatedObject.Loaded += LoadToolbar;
            }
    
            private void LoadToolbar(object sedner, RoutedEventArgs routedEventArgs)
            {
                // If no toolbar control defined in the RadGridView them then do nothing
                var toolbarControl = AssociatedObject.GetVisuals()
                    .OfType<ContentPresenter>()
                    .FirstOrDefault(control => control.Name == "PART_GridToolbar");
                if (toolbarControl == nullreturn;          
                 
                AssociatedObject.Loaded -= LoadToolbar;
     
                var vm = new RadGridViewToolbarViewModel(AssociatedObject);
                
                toolbarControl.Content = new RadGridViewToolbarControl(vm.InitToolbarView());
                toolbarControl.Visibility = Visibility.Visible;
            } 
      }
    

    And we added this toolbar as the behavior of the RadGridView:     
    <System.Windows.Interactivity:Interaction.Behaviors>
    
                   <Toolbar:RadGridViewToolbar/>

    The user can input text in this toolbar to do search in the GridView. It had been working fine until we upgraded the Telerik control to the latest version (RadControls for Silverlight Q2 2011).
    Now, whenever the user wants to do a search in the toolbar Textbox by typing a letter, the first letter can be input. However, the GridView will capture the focus now. To type the second letter, the user has to click into the textbox in the toolbar. But this time the GridView will capture the user input (second typing) directly and the second letter cannot even be displayed in the textbox. Then the user has to click into the textbox again to regain the focus, and this time the user can input the second letter.
    The same process will happen to the third letter. After the third letter, the user can use the textbox as usual.

    Since this problem affect all the GridViews in our project, could you please provide us a solution ASAP?
    I posted a similar problem last week. (http://www.telerik.com/community/forums/silverlight/gridview/gridview-captured-button-click-first-in-the-latest-release.aspx)

    Thanks a lot!
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 03 Aug 2011 Link to this post

    Hello Xinfeng,

    Please excuse us for the late reply.
    Looking at the code-snippet provided, I am not able to suggest what could be the cause of the issue. May you provide slightly more information about your application ? What is the tool bar that you are using, how is it defined, is it declared inside another control ? Generally, any relevant information that will enable me to reproduce your settings locally would be helpful. 

     

    Regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. Xinfeng
    Xinfeng avatar
    15 posts
    Member since:
    Jul 2011

    Posted 03 Aug 2011 Link to this post

    Here is more information regarding this problem. We are using Prism framework.
    http://www.telerik.com/community/forums/silverlight/gridview/problem-when-using-behavior-lt-t-gt-in-q2-2011.aspx
    http://www.telerik.com/community/forums/silverlight/gridview/gridview-captured-button-click-first-in-the-latest-release.aspx

    We created our own toolbar in a user control, then we attach the toolbar to the GridView in Behavior<RadGridView>.
    Here is the Behavior class:
    public class RadGridViewToolbar : Behavior<RadGridView>
        {
            public static string PersisterServiceKey { getset; }
            public bool ShowViews { getset; }
            public bool ShowColumns { getset; }
            public bool ShowSearch { getset; }
            public bool ShowExport { getset; }
     
            private readonly PersistRadGridView _persistBehavior = new PersistRadGridView { PersisterServiceKey = PersisterServiceKey };
     
            public RadGridViewToolbar()
            {
                ShowViews = ShowColumns = ShowSearch = ShowExport = true;            
            }
     
            protected override void OnAttached()
            {
                base.OnAttached();
                _persistBehavior.Attach(AssociatedObject);
     
                AssociatedObject.Loaded += LoadToolbar;
            }
            private void LoadToolbar(object sedner, RoutedEventArgs routedEventArgs)
            {
                // If no toolbar control defined in the RadGridView them then do nothing
                var toolbarControl = AssociatedObject.GetVisuals()
                    .OfType<ContentPresenter>()
                    .FirstOrDefault(control => control.Name == "PART_GridToolbar");
                if (toolbarControl == nullreturn;
                
                // if columns are not loaded then do nothing
                /*
                if (!AssociatedObject.Columns
                        .OfType<GridViewDataColumn>()
                        .Any(gvc => gvc.DataType != null && gvc.GetDataMemberName() != null)) return;
                */
     
                AssociatedObject.Loaded -= LoadToolbar;
     
                var vm = new RadGridViewToolbarViewModel(AssociatedObject)
                    {
                        ViewsCtrlVisibility = ShowViews ? Visibility.Visible : Visibility.Collapsed,
                        ColumnCtrlVisibility = ShowColumns ? Visibility.Visible : Visibility.Collapsed,
                        SearchCtrlVisibility = ShowSearch ? Visibility.Visible : Visibility.Collapsed,
                        ExportCtrlVisibility = ShowExport ? Visibility.Visible : Visibility.Collapsed
                    };
                
                toolbarControl.Content = new RadGridViewToolbarControl(vm.InitToolbarView());
                toolbarControl.Visibility = Visibility.Visible;
            }
     
        }
    
    
    Here is the toolbar class:

    <UserControl x:Class="Cantor.Portal.PB.Gui.Application.Toolbar.RadGridViewToolbarControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"
        xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:si="clr-namespace:Expression.Samples.Interactivity;assembly=Expression.Samples.Interactivity" xmlns:Behaviors="clr-namespace:EPF.Behaviors;assembly=EPF.Silverlight">
        
        <Border x:Name="LayoutRoot" Style="{StaticResource PanelStrip}" BorderThickness="0,0,0,1">
            <Grid>
     
                <StackPanel Grid.Column="0" Orientation="Horizontal">
                    <Border x:Name="ViewsCtrl" BorderThickness="0" Visibility="{Binding ViewsCtrlVisibility}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="VIEW" Margin="0,0,5,0" VerticalAlignment="Center" />
                            <telerikInput:RadComboBox Grid.Column="0" Style="{StaticResource StandardRadComboBox}"
                                              Width="125"
                                              ItemsSource="{Binding Views}"
                                              SelectedItem="{Binding CurrentView, Mode=TwoWay}"                                                   
                                              DisplayMemberPath="layoutName"  
                                              SelectionChanged="RadComboBox_SelectionChanged"
                                              >
                            </telerikInput:RadComboBox>
                        </StackPanel>
                    </Border>
     
                    <Border x:Name="ColumnCtrl" BorderThickness="0" Visibility="{Binding ColumnCtrlVisibility}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="COLUMNS" Margin="0,0,5,0" VerticalAlignment="Center" />
                            <telerikInput:RadComboBox Grid.Column="0" Style="{StaticResource StandardRadComboBox}" MinWidth="100" ItemsSource="{Binding Columns}" SelectionChanged="Selector_OnSelectionChanged">
                                <telerikInput:RadComboBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <CheckBox IsChecked="{Binding IsVisible, Mode=TwoWay}"/>
                                            <TextBlock Text="{Binding Header}"/>
                                        </StackPanel>
                                    </DataTemplate>
                                </telerikInput:RadComboBox.ItemTemplate>
                            </telerikInput:RadComboBox>
                        </StackPanel>
                    </Border>
     
                    <Border x:Name="FilterCtrl" BorderThickness="0" Visibility="{Binding ViewsCtrlVisibility}">
                        <StackPanel Orientation="Horizontal">
                            <telerik:RadButton Command="{Binding SaveCommand}" Style="{StaticResource StandardRadButton}">
                                <telerik:RadButton.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <Rectangle Fill="{StaticResource ButtonIconSave}" Width="16" Height="16" />
                                        <TextBlock Text="Save" Margin="4 0 0 0"/>
                                    </StackPanel>
                                </telerik:RadButton.Content>
                            </telerik:RadButton>
                            <telerik:RadButton x:Name="GridSaveAsButton" Command="{Binding SaveAsCommand}" Style="{StaticResource StandardRadButton}">
                                <telerik:RadButton.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <Rectangle Fill="{StaticResource ButtonIconSaveNew}" Width="16" Height="16" />
                                        <TextBlock Text="Save As" Margin="4 0 0 0"/>
                                    </StackPanel>
                                </telerik:RadButton.Content>
                            </telerik:RadButton>
                            <telerik:RadButton Command="{Binding DeleteCommand}" Style="{StaticResource StandardRadButton}">
                                <telerik:RadButton.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <Rectangle Fill="{StaticResource ButtonIconDelete}" Width="16" Height="16" />
                                        <TextBlock Text="Delete" Margin="4 0 0 0"/>
                                    </StackPanel>
                                </telerik:RadButton.Content>
                            </telerik:RadButton>
                        </StackPanel>
                    </Border>
     
                    <Border x:Name="SearchCtrl" BorderThickness="0" Visibility="{Binding SearchCtrlVisibility}">
                        <StackPanel Orientation="Horizontal">
                            <TextBox Width="100" Margin="10,0,0,0" Text="{Binding QuickFilterValue, Mode=TwoWay}">                            
                            </TextBox>
                            <telerik:RadButton Command="{Binding FilterCommand}" Style="{StaticResource StandardRadButton}" BorderThickness="0,1,1,1">
                                <telerik:RadButton.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <Rectangle Fill="{StaticResource ButtonIconSearch}" Width="16" Height="16" />
                                    </StackPanel>
                                </telerik:RadButton.Content>
                            </telerik:RadButton>
                        </StackPanel>
                    </Border>
     
                    <Border x:Name="ExportCtrl" BorderThickness="0" Visibility="{Binding ExportCtrlVisibility}">
                        <StackPanel Orientation="Horizontal">
                            <telerik:RadButton Command="{Binding ExcelExportCommand}" Style="{StaticResource StandardRadButton}" Margin="10,0,5,0">
                                <telerik:RadButton.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <Rectangle Fill="{StaticResource ButtonIconExportExcel}" Width="16" Height="16" />
                                        <TextBlock Text="Excel" Margin="4 0 0 0"/>
                                    </StackPanel>
                                </telerik:RadButton.Content>
                            </telerik:RadButton>
     
                            <telerik:RadButton Command="{Binding CsvExportCommand}"  Style="{StaticResource StandardRadButton}" Margin="10,0,5,0">
                                <telerik:RadButton.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <Rectangle Fill="{StaticResource ButtonIconExportCSV}" Width="16" Height="16" />
                                        <TextBlock Text="CSV" Margin="4 0 0 0"/>
                                    </StackPanel>
                                </telerik:RadButton.Content>
                            </telerik:RadButton>
     
                            <telerik:RadButton Command="{Binding PrintCommand}" Style="{StaticResource StandardRadButton}" Margin="10,0,5,0">
                                <telerik:RadButton.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <Rectangle Fill="{StaticResource ButtonIconPrinter}" Width="16" Height="16" />
                                        <TextBlock Text="Print" Margin="4 0 0 0"/>
                                    </StackPanel>
                                </telerik:RadButton.Content>
                            </telerik:RadButton>
                        </StackPanel>
                    </Border>
                </StackPanel>
            </Grid>
        </Border>
     
    </UserControl>

    Code behind:
    public partial class RadGridViewToolbarControl
        {
            public RadGridViewToolbarControl(RadGridViewToolbarViewModel viewModel)
            {
                InitializeComponent();
                DataContext = viewModel;
            }
     
            private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                var comboBox = sender as RadComboBox;
                if (comboBox != null)
                {
                    comboBox.SelectedItem = null;
                }
            }
     
            private void RadComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                var vm = DataContext as RadGridViewToolbarViewModel;
                if (vm == null) return;
     
                vm.UpdateView();
            }
        }

    Then in the GridView we do this:        

    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
          <telerikGridView:RadGridView
                                         ItemsSource="{Binding Balances}"
                                         Style="{StaticResource StandardRadGridView}"
                                         BorderThickness="0,0,0,1"
                                         SelectionMode="Extended"
                                         SelectionUnit="Cell"
                                         ClipboardCopyMode="Cells"                                     
                                         AutoGenerateColumns="False"
                                         IsFilteringAllowed="True"
                                         CanUserSortColumns="True"
                                         CanUserReorderColumns="True"
                                         CanUserFreezeColumns="True"
                                         FrozenColumnCount="1"                                         
                                         CanUserResizeColumns="True"
                                         ShowColumnFooters="True"   
                                         x:Name="accountBalances"
                                         EnableRowVirtualization="True"
                                         EnableColumnVirtualization="True">
                                        
                                        <i:Interaction.Behaviors>
                                            <Toolbar:RadGridViewToolbar/>






  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 04 Aug 2011 Link to this post

    Hello Xinfeng,

    Despite my wish to recreate your scenario on a separate project, I was not able to as there are some missing part that I am not aware to. However, based on the description of inserting characters in a TextBox and loosing the focus, I have developed an new application trying to simulate your case.
    Please take a look and let me know whether I need to extend it in a way so that it will correspond to your scenario.
    If this project is not sufficient for the current issue to be resolved, it would be great if you could send us a small runnable application that will help us understand your specific settings and requirements. Generally, this is the fastest way for resolving a problem as there is no guessing from our side.
    Thank you for the cooperation.

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  5. Xinfeng
    Xinfeng avatar
    15 posts
    Member since:
    Jul 2011

    Posted 05 Aug 2011 Link to this post

    Hi Maya,

    Thanks a lot for your help! At present, we are very busy with our project. And we worked around this problem in our code, we will try to create a small demo project to show you the bug in the future when we have time.

    We are not simply using a button or textbox outside of the GridView. We define the toolbar in the template and use Behavior to attach the toolbar to the GridView.

    Regards,

    Xinfeng
  6. Xinfeng
    Xinfeng avatar
    15 posts
    Member since:
    Jul 2011

    Posted 01 Sep 2011 Link to this post

    Hi Maya,

    I build a demo project for the bug. However, the project itself is much bigger than 2MB. Could you please tell me how I can upload the project files?

    Thanks a lot!

    Xinfeng
  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 02 Sep 2011 Link to this post

    Hi Xinfeng,

    You will be able to upload a sample project of about 20MB if you open a support ticket and attach it there.
     

    Best wishes,
    Maya
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top