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

4 posts, 1 answers
  1. Khanh
    Khanh avatar
    25 posts
    Member since:
    Sep 2019

    Posted 20 Sep 2019 Link to this post

    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

     

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2916 posts

    Posted 20 Sep 2019 Link to this post

    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.
  3. Khanh
    Khanh avatar
    25 posts
    Member since:
    Sep 2019

    Posted 20 Sep 2019 in reply to Dimitar Link to this post

    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 :)

  4. Dimitar
    Admin
    Dimitar avatar
    2916 posts

    Posted 23 Sep 2019 Link to this post

    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.
Back to Top