Select ListView Item as Though it had been Clicked

  • Thread starter Thread starter Jonathan Wood
  • Start date Start date
J

Jonathan Wood

I'm adding items to a ListView control. As I add each item, I want to
*properly* select that new item--as though it had been clicked with the
mouse. This means it will be the only highlighted item, it will get the
focus rectangle if the control has focus, and the control will scroll if
needed to fully display the selected item.

Apparently, it was assumed this would not be a useful task.

So far, I've come up with the following.

lvwInfo.SelectedItems.Clear();
item.Selected = true;
item.Focused = true;
lvwInfo.Items.Add(item);

It kind of works, but it does not scroll to fully display the selected item.

Please tell me I'm missing something easy here, instead of that I need yet
more code to accomplish this trivial task.

Thanks.

Jonathan
 
focus rectangle if the control has focus, and the control will scroll if
needed to fully display the selected item.
Apparently, it was assumed this would not be a useful task.
So far, I've come up with the following.
      lvwInfo.SelectedItems.Clear();
      item.Selected = true;
      item.Focused = true;
      lvwInfo.Items.Add(item);
It kind of works, but it does not scroll to fully display the selected item.

Check EnsureVisible method.
 
Yeah, I found that. I just can't understand though why a single method
wasn't added that can handle this.

Thanks.

Jonathan

Josip Medved said:
focus rectangle if the control has focus, and the control will scroll if
needed to fully display the selected item.
Apparently, it was assumed this would not be a useful task.
So far, I've come up with the following.
lvwInfo.SelectedItems.Clear();
item.Selected = true;
item.Focused = true;
lvwInfo.Items.Add(item);
It kind of works, but it does not scroll to fully display the selected
item.

Check EnsureVisible method.
 
Back
Top