Select ListView Item as Though it had been Clicked

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
 
J

Josip Medved

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.
 
J

Jonathan Wood

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top