DataGrid select item on user keypress

Posted by: jagdeeshk on 30 December 2019, 12:48 am EST

    • Post Options:
    • Link

    Posted 30 December 2019, 12:48 am EST

    Hello,

    I am trying to implement on key press to navigate respective row. suppose when i press letter A, it will navigate to first row where row start with letter A and if user press more than one letter continuously it will navigate to row which start with string.

    private void DataGridViewOfUsersList_KeyDown(object sender, KeyEventArgs e)
            {
                C1.WPF.DataGrid.C1DataGrid dataGrid = sender as C1.WPF.DataGrid.C1DataGrid;
                for (int i = 0; i < (dataGrid.Rows.Count); i++)
                {
                    UsersList usersList = (UsersList)dataGrid[i, 0].Value;
                    string fullName = usersList.user_FullName.ToLower();
                    if (fullName.StartsWith(e.Key.ToString().ToLower(), true, CultureInfo.InvariantCulture))
                    {
                        dataGrid.SelectedIndex = i;
                        dataGrid.ScrollIntoView(1,0);
                        return;
                    }
                }
            }
    

    I implemented like this but it working only for single character. if user press more than one character they are navigating one by one. Is there any way to implement ?

    Thanks,

    Jagdeesh.

  • Posted 30 December 2019, 8:48 pm EST - Updated 4 October 2022, 12:00 am EST

    Hello Jagdeesh,

    I understood your requirement. Based on my understanding, I have prepared an application and attached here.

    Also, attached is its output. Is this what you needed? If yes, I would request you to kindly refer the attached application.

    Regards,

    RuchirSelectRow_KeyPress_C1WPF.zip

  • Posted 30 December 2019, 10:23 pm EST

    Thank you, Working fine.

    Thanks,

    Jagdeesh.

  • Posted 30 December 2019, 10:37 pm EST

    Glad, we could help.

    Wish you A Very Happy New Year!!

    ~Ruchir

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels