开发者

List View in C#

开发者 https://www.devze.com 2022-12-09 16:07 出处:网络
I have a ListView in my C#开发者_高级运维 and I want to select an item based on a number which I give. Is this possible ?

I have a ListView in my C#开发者_高级运维 and I want to select an item based on a number which I give. Is this possible ?

Example: if my List which has add , multiply and divide as elements in list . so if I give 2 it must select multiply. All these must be done programatically


Looks like you want to select an item by it's index.

If it's for WinForms, you can clear the SelectedIndices collection, and add your item index:

listView.SelectedIndices.Clear();
listView.SelectedIndices.Add(yourIndex);

For WebForms, you have the SelectedIndex property:

listView.SelectedIndex = yourIndex;

Remember that the indexes are zero-based.


If it's the ListItem value is 2 - I'd simply go with:

_listView.SelectedValue = "2";

or perhaps more correctly:

_listView.SelectedValue = _input.ToString();
0

精彩评论

暂无评论...
验证码 换一张
取 消