Question control to display image and name?

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
What would be the best control to use if i want to parse all the images from a webpage and display them and their name. Would a listview be good choice? What if i also want to be able to group them into different groups?
 
can each images in the listview have different size? can the imagelist have different size images?
 
Group

how do i add item to this group? i know i can use .Group(0) to add to the first group. But can i use the group name to add?

VB.NET:
Dim name as string = "Test"
ListView1.Groups.Add(New ListViewGroup(name)) 

Dim item As New ListViewItem("ABC")

item.Group = ListView1.Groups(0)

ListView1.Items.Add(item)
 
Your using the Item property of the Groups collection there, and it does accept a numeric index or a text key. In order to use a key to retrieve a group, you have to have added that group with a key in the first place. The ListViewGroup constructor that you're using provides text only, not a name.
 
Is there other controls that can have multiple images? seems listview limit the size to 256x256, is there one that support bigger?
 
I notice the groups are automatically sorted ascending order. can you reverse the group sort to descending?
 
Listview

Then can you also include a link? Or at least tell me I need to write a comparer or something helpful. Instead of blaming me for asking a question in a forum. You can find it in 20 sec that is why I am asking you. I still can't find one I understand in 20 minutes.
 
Last edited:
I'm rather curious. What keywords did you use to search? I mean, you want to sort groups in a ListView in VB.NET. How hard is it to pick the keywords out of that statement? It just worries me greatly the number of people who want to write software but can't search the web effectively. I'm all for helping people with difficult things but when I Googled vb.net sort groups listview the very first result was a solution to your problem. There really is no valid reason that you couldn't find that yourself. Now, admittedly, the code is C#, but it's simple code and most VB developers should be able to read most if not all of it. There are online code converters that shouldn't have issue with it anyway. I just see a great many people using forums not as a way to solve a problem but as a way to avoid thinking or trying too hard long before a problem even arises.
 
It is not that i didn't find the C# one, i just don't know how to use it. If you use converter to convert the code, there would be errors that i don't know how to fix.

like this line become this and error
VB.NET:
[COLOR=blue]public[/COLOR] [COLOR=blue]class[/COLOR] ListViewGroupHeaderSorter : IComparer<ListViewGroup>
VB.NET:
Public Class ListViewGroupHeaderSorter
    Implements IComparer(Of ListViewGroup)

also this error
VB.NET:
[COLOR=blue]public[/COLOR] [COLOR=blue]static[/COLOR] [COLOR=blue]bool[/COLOR] [COLOR=blue]operator[/COLOR] ==(ListView listview, ListViewGroupSorter sorter)    {        [COLOR=blue]return[/COLOR] listview == sorter._listview;    }    
[COLOR=blue]public[/COLOR] [COLOR=blue]static[/COLOR] [COLOR=blue]bool[/COLOR] [COLOR=blue]operator[/COLOR] !=(ListView listview, ListViewGroupSorter sorter)    {        [COLOR=blue]return[/COLOR] listview != sorter._listview; [COLOR=black][FONT=Consolas]    }
[/FONT][/COLOR]
VB.NET:
    Public Shared Operator =(listview As ListView, sorter As ListViewGroupSorter) As Boolean
        Return listview = sorter._listview
    End Operator
    Public Shared Operator <>(listview As ListView, sorter As ListViewGroupSorter) As Boolean
        Return listview <> sorter._listview
    End Operator

and this
VB.NET:
((ListViewGroupSorter)listView1).SortGroups([COLOR=blue]false[/COLOR]);
VB.NET:
        DirectCast([COLOR=black][FONT=Consolas]listView1[/FONT][/COLOR], ListViewGroupSorter).SortGroups(False)
 
Last edited:
Then that should have been what you asked about, e.g.
I found this but I'm having these problems converting it:
That said, I can't really see any real issue with those conversions. Most likely they can all be easily fixed with a bit of thought about what VB actually requires. For instance, if I had to guess I would say that the issue with the first snippet is that the IComparer(Of T) interface or the ListViewGroup class is not defined. That's simply a namespace issue and, as is always the case when writing VB code, you need to either fully qualify the type or import the namespace.
 
Here's the code example from the MSDN documentation for the Implements statement:
Public Interface ICustomerInfo
      Event updateComplete()
      Property customerName() As String
      Sub updateCustomerStatus()
  End Interface
  
  Public Class customerInfo
      Implements ICustomerInfo
      ' Storage for the property value.
      Private customerNameValue As String
      Public Event updateComplete() Implements ICustomerInfo.updateComplete
      Public Property CustomerName() As String _
          Implements ICustomerInfo.customerName
          Get
              Return customerNameValue
          End Get
          Set(ByVal value As String)
              ' The value parameter is passed to the Set procedure
              ' when the contents of this property are modified.
              customerNameValue = value
          End Set
      End Property
  
      Public Sub updateCustomerStatus() _
          Implements ICustomerInfo.updateCustomerStatus
          ' Add code here to update the status of this account.
          ' Raise an event to indicate that this procedure is done.
          RaiseEvent updateComplete()
      End Sub
  End Class
Notice how the implemented members have an Implements clause on the declaration? That's a requirement in VB but there's no equivalent in C#. It's hard for me to recall what VS does of its own accord because I've been using the ReSharper add-in for a long time but, if I'm not mistaken, if you type the class declaration yourself then the IDE will generate a default implementation for all the interface members for you, complete with the Implements clauses
 
ok i figure out whats wrong with the implements but what does these 2 operator do? It seems to sort just fine if i comment them out. They give error. Operator = is not defined for type System.windows.forms.listview and system.windows.form.listview

VB.NET:
    Public Shared Operator =(listview As ListView, sorter As ListViewGroupSorter) As Boolean
        Return listview = sorter._listview  'ERROR
    End Operator
    Public Shared Operator <>(listview As ListView, sorter As ListViewGroupSorter) As Boolean
        Return listview <> sorter._listview  'ERROR
    End Operator
 
Back
Top