选择ListView控件的第一行 [英] Select the first row of ListView control

查看:85
本文介绍了选择ListView控件的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含文本框和Listview的表单,显示来自SQL表的记录.
现在我的列表视图根据我的文本框的标准进行填充.一切都很好.

我的问题是,当我按下文本框中的向下箭头时,它应聚焦于列表视图并选择列表视图控件的第一行.我写的代码是

I have a form contains a textBox and Listview displaying records from a SQL Table.
Now my listview populating depending on the criteria of my textbox.Everything is perfectly working.

My problem is when I press the down arrow from my textbox it should focus the listview and select the first row of the listview control. I have written a code as

private void textBox1_KeyDown(object sender, KeyEventArgs e)
       {
           if (e.KeyData == Keys.Down)
               listView1.Focus();
       }



这段代码将焦点集中在列表视图上,当我第二次按下向下箭头时,它正在选择第二行.
我的问题是,它正在选择第一行,但它不可见.就像焦点在列表视图中时,当我下次按下向上或向下箭头时发生的那样.

我想要的是,当listview获得焦点时,它应该选择第一行,并且应该通过颜色变化(例如蓝色背景和白色前景)可见.



this code is focus the listview and when I press down arrow second time it is selecting second row.
My problem is, it is selecting the first row but it is not visible. like it happens when I press up or down arrow for next time after the focus is in the listview.

what i want is when the listview got the focus it should select the first row and that should visible by color changes (like blue background and white foreground)

推荐答案

设置listView1.Items[0].Selected = true;


这篇关于选择ListView控件的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆