ListView EnsureVisible doesn't work

A

Alex

Hello everybody,
On some reason EnsureVisible( nSelInd ) for ListView doesn't work in
my C# project. Here is the code:

this.listCategories.Items[nSelInd].Selected = true;

//neither
this.listCategories.EnsureVisible(nSelInd);

//nor
this.listCategories.Items[nSelInd].EnsureVisible();

are not working. Selected row remains hidded at the bottom of list
view.
"Scrollable" property is set to true. What else I'm not doing right?

Thanks,
Alex
 
A

Alex

One more thing I've noticed. Everything is fine if the dialog with
the list view has been shown already. EnsureVisible works Ok.
The problem occures when I'm calling EnsureVisible when I'm
initializing controls of the dialog (including list view) before
calling
if( dlg.ShowDialog ... from the parent Form.

Maybe in this case it cannot be done at all? Is it Microsoft bug?
 
J

Josip Medved

On some reason EnsureVisible( nSelInd ) for ListView doesn't work in
"Scrollable" property is set to true.  What else I'm not doing right?

Hi,

EnsureVisible has no effect if ListView is not visible. You may put
call
to it in Shown event or use TopItem property instead. That property
works
while control is not displayed.
 
J

Josip Medved

One more thing I've noticed.  Everything is fine if the dialog with
the list view has been shown already.  EnsureVisible works Ok.
The problem occures when I'm calling EnsureVisible when I'm
initializing controls of the dialog (including list view)
Maybe in this case it cannot be done at all?  Is it Microsoft bug?

Whether it is bug or not it is difficoult to say. To me it seems that
that piece code is tied together with painting code of control and
that code is not executed while control is not visible (maybe
because of custom drawing). But that is just a guess.
 
A

Alex

Thanks Josip for your answer,

Indeed, because I want to select and make this selected record visible
before I call dlg.ShowDialog(), the list view is not show also...

It seems to me very inconvinient, but I'll try to use your advices.

Best regards,
Alex
 
A

Alex

line of the code:

this.listCategories.TopItem = this.listCategories.Items[nSelInd];

works fine, thanks again Josip
 

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