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();
精彩评论