How to select an item in a ListView programmatically?

前端 未结 7 1518
野趣味
野趣味 2020-12-08 09:13

I\'m trying to select the first item in a ListView programmatically, but it doesn\'t appear to have been selected. I am using the following code:

if (listVie         


        
7条回答
  •  渐次进展
    2020-12-08 09:39

    I know this is an old question, but I think this is the definitive answer.

    listViewRamos.Items[i].Focused = true;
    listViewRamos.Items[i].Selected = true;
    listViewRemos.Items[i].EnsureVisible();
    

    If there is a chance the control does not have the focus but you want to force the focus to the control, then you can add the following line.

    listViewRamos.Select();
    

    Why Microsoft didn't just add a SelectItem() method that does all this for you is beyond me.

提交回复
热议问题