吾爱去(52qu) 壹曲阳勇发布个人作品之网站

C#的listView控件使用全选

C#的listView控件使用全选。可以通过以下事件完成:

        private void listView_KeyPress(object sender, KeyPressEventArgs e)

        {

            if (e.KeyChar == (char)(Keys.ControlKey & Keys.A))

            {

                var m_listview = sender as ListView;

                if (m_listview.Items.Count > 0)

                {

                    //Ctrl+A全选、全消'\u0001'

                    var m_选择 = m_listview.Items[0].Selected;

                    foreach (ListViewItem item in m_listview.Items)

                    {

                        item.Selected = !m_选择;

                    }

                }

            }

        }

这样,在以第一个项的为反向全选择。


2022年4月8日 | 发布:程序员 | 分类:编程 | 评论:0

发表留言: