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

RadGrid Focus issue

5 Answers 77 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 05 Nov 2015, 10:33 AM

Hello,

I am using silverlight RadGridView control and facing focus issue as below.

For example, my gridview has 3 rows. by pressing tab currently I am on second row.

Now suppose I am directly move focus on another controls by some shortcuts or by mouse.

Now if I will get focus again on RadGridView then focus starting from
second row(previously focused row) instead I want to be start focus from
first row.

I'll appreciate your immediate response on this.

Thanks.

5 Answers, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 06 Nov 2015, 11:06 AM
 Hi Eric,

I have implemented this behavior in a project with a RadGridView and a simple button, handling the SelectionChanged event. You can use the same approach by setting the canSelect value to true in the other controls you have. Please refer to the following code snippet: 
private bool canSelect;

private void Button1_Click(object sender, RoutedEventArgs e)
        {
            canSelect = !canSelect;
        }
 
        private void clubsGrid_SelectionChanged(object sender, SelectionChangeEventArgs e)
        {
            if (canSelect)
            {
                this.clubsGrid.SelectedItem = this.clubsGrid.Items[0];
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    this.clubsGrid.CurrentCellInfo = new GridViewCellInfo(this.clubsGrid.SelectedItem, this.clubsGrid.Columns[0]);
                }));
            }
        }

Please, update me if the information was helpful.

Regards,
Stefan Nenchev
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
0
Eric
Top achievements
Rank 1
answered on 16 Nov 2015, 10:39 AM

Hello Stefan,

Thanks for your reply.

As this solution won't work for me. Once we will make variable true, we won't​ able to move forward with Tab to other row of RadGridView because ​on_SelectionChanged event we are selecting first item every time.

I think, ​there should be some modification on focus lost but focus lost event executing even if we are moving within RadGridView Column/Rows.

Please can you provide some alternate solution.

Thanks.

0
Stefan Nenchev
Telerik team
answered on 16 Nov 2015, 03:59 PM
Hi Eric,

In order to be able to change the selected item after that, you can again change the canSelect variable to false, as in the code snippet below:

private void clubsGrid_SelectionChanged(object sender, SelectionChangeEventArgs e)
{
    if (canSelect)
    {
        this.clubsGrid.SelectedItem = this.clubsGrid.Items[0];
        Dispatcher.BeginInvoke(new Action(() =>
        {
            this.clubsGrid.CurrentCellInfo = new GridViewCellInfo(this.clubsGrid.SelectedItem, this.clubsGrid.Columns[0]);
        }));
        canSelect = false;
    }
}

I have tested it from my end and it works as expected so I hope it will suit your needs.

Regards,
Stefan Nenchev
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
0
Eric
Top achievements
Rank 1
answered on 17 Nov 2015, 09:47 AM

Hello Stefan,
As I have mentioned in my post description, If I am directly move focus on another controls by some shortcuts or by mouse then  RadGridView selected item remain last selected ​Item instead of I want first item like you did.

Also _SelectionChanged will be executed ​every time when you will  do change RadGridView rows/columns. In your code snippet, you have changed canSelect on button click while in my case I don't have specific control on which I can make it true/false, as there are many controls in my form.

​My goal is when you lost focus from RadGridView control and if get focus again on RadGridView  then it should be first row of  RadGridView controls instead of previous selected row.

Let me know if you need anymore clarification from me.

Thanks.

0
Stefan Nenchev
Telerik team
answered on 17 Nov 2015, 04:02 PM
Hi Eric,

I have suggested this implementation, and not directly to attach to the LostFocus event, as the RadGridView uses all focus-related events for some internal operations and using them in your logic can cause inconsistent actions and results.

You don`t have to implement the previously mentioned logic in the SelectionChanged event of the RadGridView. I just used it as an example. Instead, you can set it every time another control is clicked or gets focused. So you can attach this to the GotFocus method of a simple button, or any other control you have included in your project, let`s say a button:
private void Button_GotFocus(object sender, RoutedEventArgs e)
        {
            this.clubsGrid.SelectedItem = this.clubsGrid.Items[0];
            Dispatcher.BeginInvoke(new Action(() =>
            {
                this.clubsGrid.CurrentCellInfo = new GridViewCellInfo(this.clubsGrid.SelectedItem, this.clubsGrid.Columns[0]);
            }));
             
        }

  

Regards,
Stefan Nenchev
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
GridView
Asked by
Eric
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Eric
Top achievements
Rank 1
Share this question
or