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

[Solved] GridView captured button click first in the latest release

2 Answers 124 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Xinfeng
Top achievements
Rank 1
Xinfeng asked on 20 Jul 2011, 03:11 PM
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 click the buttons in this toolbar to do all kinds of export stuff. It had been working fine until we upgraded the Telerik control to the latest version (RadControls for Silverlight Q2 2011).
Now, if the GridView is not empty, the first cell will be selected instead of running the button click event handler whenever the user first time click the button in the custom toolbar. After the first time click, the buttons behave normally. It seems that after the GridView is populated with data, it will swallow the first time button click event in the custom toolbar.

Since this problem affect all the GridViews in our project, could you please provide us a solution ASAP?

Thanks a lot!

  

2 Answers, 1 is accepted

Sort by
0
Xinfeng
Top achievements
Rank 1
answered on 20 Jul 2011, 03:45 PM
Attachment is the custom toolbar I was talking about. The first time button click event is swallowed by the GridView in the latest Q2 11 version.
0
Xinfeng
Top achievements
Rank 1
answered on 20 Jul 2011, 04:12 PM
I found a quick fix for this issue. I think it might be helpful for you guys to figure out the reason.
After I set the focus to the first cell of the GridView, the GridView will not swallow my first time
button click in the custom toolbar anymore.

void
GridView_DataLoaded(object sender, EventArgs e)         {                        if (Control.HasItems)             {                 Control.CurrentCellInfo = new GridViewCellInfo(Control.Items[0], Control.Columns[0]);                 Control.Focus();             }         }
Tags
GridView
Asked by
Xinfeng
Top achievements
Rank 1
Answers by
Xinfeng
Top achievements
Rank 1
Share this question
or