以编程方式选择listview行 [英] Selecting the listview rows programitally
本文介绍了以编程方式选择listview行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我有一个包含行数的listview,以及当我在textbox中编写文本时(例如:10)
那么我需要在C#.net中以编程方式在列表视图中选择任意十行
我曾经尝试过类似
Hi
I had an listview that contains number of rows ,and one textbox box when i write in textbox(eg:10)
then i need to select any ten number of rows in listview, throught programatically in C#.net
i had tried with something like
for (int i = 0; i < int.Parse(textBox1.Text); i++)
{
checkedListView.SelectedItem = checkedListView.Items[i];
}
但是通过这种方式,iam只能在listview中选择单行
所以请帮助达到此要求
<高级
but by this thing iam only able to select single row in listview
so please help to achive this requirement
thankq in advanced
推荐答案
如果MultiSelect
设置为true
,则可以使用Selected
属性.
http://msdn.microsoft.com/en-us/library/system.windows.forms.listviewitem.selected.aspx [ ^ ]
IfMultiSelect
is set totrue
, you can useSelected
property.
http://msdn.microsoft.com/en-us/library/system.windows.forms.listviewitem.selected.aspx[^]
for (int i = 0; i < int.Parse(textBox1.Text); i++)
{
checkedListView.Items[i].Selected = true;
}
看看 ^ ],这可能会有所帮助.
Take a look at the SelectedIndexCollection[^], it may help.
您应该将每个选择的属性设置为true.这样的东西
You should just set each items selected property to true. Something like this
int amountToSelect = 0;
int.TryParse(textBox1.Text,out amountToSelect);
for (int i = 0; i <= amountToSelect; i++)
{
listView1.Items[i].Selected = true;
}
希望对您有帮助
Hope this helps
这篇关于以编程方式选择listview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文