简体   繁体   English

如何防止 C# WinForm 列表视图选择更改时按下键和列表视图在第一列的基础上自动查找下一行

[英]How to prevent C# WinForm listview selection Change when key is pressed and list view auto find next row on the basis of first column

My listview is populated from DB table When I press a number key the list view auto find that key in first column and change selection to that item.我的列表视图是从 DB 表填充的当我按下数字键时,列表视图会自动在第一列中找到该键并将选择更改为该项目。 I haven't written any code for that purpose.我没有为此目的编写任何代码。 I want to stop doing this.我想停止这样做。

For finding item by first column when key pressed in ListView:在 ListView 中按下键时按第一列查找项目:

        private void listView1_KeyUp(object sender, KeyEventArgs e)        
        {
            var i = 0;
            var data = listView1.Items.Cast<ListViewItem>()
                                 .Select((a,b)=>new { itemText = a.Text, index = i++ })
                                 .ToList();
            var findItem = data.Where(w => w.itemText.StartsWith(e.KeyValue.ToString())).FirstOrDefault();
            if (findItem == null)
                return;

            listView1.Items[findItem.index].Focused = true;
            listView1.Items[findItem.index].Selected = true;
            listView1.Items[findItem.index].EnsureVisible();
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WPF DataGrid:如何防止按Enter键时自动更改行? - WPF DataGrid: How to prevent auto change row on enter key pressed? 在C#WinForm ListBox上,如何通过按下一个键清除对多个项目的选择? - On C# WinForm ListBox how to clear the selection of multiple items with a key pressed? 当在c#winform中按下PageDown键时,如何触发Button Click事件 - How can I fire a Button Click event when PageDown key pressed in c# winform C#ListView阻止选择 - C# ListView prevent selection 按下TAB键时如何捕捉Winform - How to catch on a winform when the TAB key is pressed 如何将复选框添加到c#Winform应用程序中的列表视图列标题? - How to Add a Checkbox to a List View Column Header in c# Winform App? 如何分配列表<object>在 c# 和 winForm 中选择行时到 dataGridView 并获取单个对象? - How to assign list<object> to dataGridView and get single object when select row in c# and winForm? C#:按下Enter键时更改DropDownList值 - C#: Change DropDownList value when Enter key is pressed C# - 当前行填满时如何防止光标跳转到下一行 - C# - How to prevent cursor from jumping to next row when the current row fills up C#,winform-使用向上和向下箭头键选择列表框? - C#, winform - List box selection using up and down arrow key?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM