ListView Methods

dlfallen

Active Member
Licensed User
Longtime User
Erel, are there plans to implement the setSelection method for ListView? This would allow me to implement search functions on a long list and display the found item at the top of the displayed ListView.

Another useful method would be addHeaderView, although this one is easier to work around.
 

HarleyM

Member
Licensed User
Longtime User
Wish : a means of scrolling the listview programatically...

..and a means of highlighting (or other emphasising method) a chosen list item also programatically, would be nice is the application I'm working on.
 

HarleyM

Member
Licensed User
Longtime User
Further to using SetSelection method - Possible bug?

You can scroll the list with SetSelected methd.

I've looked at trying to get the SetSelection method to work... Perhaps I haven't understood this properly but I've tried to use it as follows (abreviated because there's a lot of other code which inserts BMP's one & two line items dependent on other factors etc) :

So after a data change or an array pointer change, I recreate Listview from the array contents, changing the Listview colour at MyIndex where Bar1 is a Listview1 label...

For Row = 0 To listSize-1
If Row = MyIndex Then
Bar1.Color = Colors.Yellow
Else
Bar1.Color = Colors.Transparent
End If
ListView1.AddTwoLines(Rec.Area,Rec.Description)
Next
Listview1.SetSelection(MyIndex)

...in the hope that the listview would show the selected item in the view with a yellow band running through it.

The result doesn't show a yellow band or scroll to reveal the MyIndex position. Sometimes I get multiple yellow bands however (which I'm also scratching my head about). Is this the way in which SetSelection is intended to be used?

Thanks
 

Inman

Well-Known Member
Licensed User
Longtime User
SetSelection(Index) simply scrolls the listview so that the item at Index is on the top. It doesn't set any background color to indicate the selection. It is understood that the item at the top is the selected item.

Now regarding Listview item background colors, you cannot set a particular background color for a particular row alone. Listview has 3 types of layouts - SingleLine, TwoLines, TwoLinesandBitmap. If you set the bg color of, say the SingleLine, all SingleLine items of that listview will have the same color.

I see that you are using TwoLines layout. Now what you can do is define one bg color for TwoLines and another color for TwoLinesandBitmap. After that you can remove the bitmap inside TwoLinesandBitmap with Listview1.TwoLinesAndBitmap.ImageView.RemoveView, so that it becomes identical to TwoLines. Inside the loop, add all items with TwoLines, except when Row = MyIndex, add that particular row with TwoLinesandBitmap. That way, that particular row will inherit the bg color of TwoLinesandBitmap while the others will get the color of TwoLines.
 

HarleyM

Member
Licensed User
Longtime User
Hey Inman, thanks a lot for explaining this.

Is there a place where this type of information resides? I generally go through the tutorials & experiment a lot, but it seems to me that I'm probably missing much in my understanding, just because it may not be specifically covered in the tutorials.

Thanks again!

Edit : I've just read through the listview tutorial again & it does explain this - somehow I missed it before!
 
Last edited:
Top