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

How i can Move between subitems in Listview Multi columns using tab Key

3 Answers 10 Views
This is a migrated thread and some comments may be shown as answers.
Khanh
Top achievements
Rank 1
Khanh asked on 20 Sep 2019, 08:41 AM
Normally in radlistview with multi Rows and Columns I can use arrowkey to move between subitems but my intention is to use tab to move faster, I wrote this code but it didn't work (using tabkey to activate arrowkey)
My initial idea was to locate the subitems (via the current column and the current listviewdataitem however I didn't know how to activate the subitems) like using vba to activate a certain cell in excel: Cells ( 1,1) .activate but I haven't found this function yet
Can you tell me can do it or not?
thanks you.
'---------------------------------
 
Private Sub RadListview_PreviewKeyDown(sender As Object, e As PreviewKeyDownEventArgs) Handles RadListview.PreviewKeyDown
        If Not (e.Modifiers = Keys.Shift) AndAlso e.KeyCode = Keys.Tab Then
            My.Computer.Keyboard.SendKeys("{right}", True)
            'SendKeys.Send("{right}")
 
        ElseIf e.Modifiers = Keys.Shift AndAlso e.KeyCode = Keys.Tab Then
 
            SendKeys.Send("{left}")
        End If
    End Sub

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 20 Sep 2019, 09:48 AM

Hi Khanh, 

The PreviewKeyDown event is not suitable for this since you cannot suppress the keypress. You can create a custom control and override the ProcessDialogKey method:

public class MyListView : RadListView
{
    protected override bool ProcessDialogKey(Keys keyData)
    {
        if (keyData == Keys.Tab)
        {
            var view = this.ListViewElement.ViewElement as DetailListViewElement;
            var element = this.ListViewElement;
            int columnIndex = element.Columns.IndexOf(element.CurrentColumn);

            ITraverser<ListViewDetailColumn> colEnumerator = (ITraverser<ListViewDetailColumn>)view.ColumnScroller.Traverser.GetEnumerator();
            colEnumerator.Position = columnIndex;

            if (colEnumerator.MoveNext())
            {
                var isEditing = element.IsEditing;

                element.CurrentColumn = colEnumerator.Current;
                if (isEditing)
                {
                    element.BeginEdit();
                }
                return true;
            }
            else
            {
                ListViewTraverser enumerator = view.Scroller.Traverser.GetEnumerator() as ListViewTraverser;
                enumerator.Position = element.CurrentItem;

                if (enumerator.MoveNext())
                {
                    var isEditing = element.IsEditing;


                    colEnumerator.Reset();
                    colEnumerator.MoveNext();
                    element.CurrentColumn = colEnumerator.Current;
                    element.CurrentItem = enumerator.Current;
                    element.SelectedItem = enumerator.Current;

                    if (isEditing)
                    {
                        element.BeginEdit();
                    }

                    return true;
                }
            }


        }
        if (keyData == (Keys.Tab | Keys.Shift))
        {
            var view = this.ListViewElement.ViewElement as DetailListViewElement;
            var element = this.ListViewElement;
            int columnIndex = element.Columns.IndexOf(element.CurrentColumn);

            ITraverser<ListViewDetailColumn> colEnumerator = (ITraverser<ListViewDetailColumn>)view.ColumnScroller.Traverser.GetEnumerator();
            colEnumerator.Position = columnIndex;

            if (colEnumerator.MovePrevious())
            {
                var isEditing = element.IsEditing;

                element.CurrentColumn = colEnumerator.Current;

                if (isEditing)
                {
                    element.BeginEdit();
                }
                return true;
            }
            else
            {
                ListViewTraverser enumerator = view.Scroller.Traverser.GetEnumerator() as ListViewTraverser;
                enumerator.Position = element.CurrentItem;

                if (enumerator.MovePrevious())
                {
                    var isEditing = element.IsEditing;

                    colEnumerator.MoveToEnd();
                    element.CurrentColumn = colEnumerator.Current;
                    element.CurrentItem = enumerator.Current;
                    element.SelectedItem = enumerator.Current;

                    if (isEditing)
                    {
                        element.BeginEdit();
                    }

                    return true;
                }
            }
        }
        return base.ProcessDialogKey(keyData);
    }
} 

I hope this helps. Should you have any other questions, do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Khanh
Top achievements
Rank 1
answered on 20 Sep 2019, 02:10 PM

Hi Dimitar !

so nice,it works like a charm :D
I was thinking of ignoring the editing case because I thought it would complicate the problem, but you quickly solved the problem.

thanks you :)

0
Dimitar
Telerik team
answered on 23 Sep 2019, 05:04 AM

Hi Khanh,

I am glad that this works for you. Do not hesitate to contact us if you have other questions.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Asked by
Khanh
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Khanh
Top achievements
Rank 1
Share this question
or