Results 1 to 3 of 3

Thread: Button As Listview Subitem?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    84

    Button As Listview Subitem?

    Is this possible?

    I need to have a button in each row of my listview, but it doesn't look like it can be done. here is my listview code so far.

    Code:
     Me.TextBox1.Enabled = True
            Me.Button3.Enabled = True
    
            Using connection As New MySqlConnection(";")
    
                Me.ListView1.Items.Clear()
    
    
                Using command As New MySqlCommand("SELECT   name, type, uploaded, uploader, location FROM programs", connection)
    
                    connection.Open()
                    Using reader As MySqlDataReader = command.ExecuteReader()
    
                        While (reader.Read())
                            Dim name As String = reader("name")
                            Dim type As String = reader("type")
                            Dim uploaded As String = reader("uploaded")
                            Dim uploader As String = reader("uploader")
                            Dim location As String = reader("location")
    
                           
                            Dim strKey As String = location
    
                            Dim lst As ListView = Me.ListView1
    
                          
                            If Not lst.Items.ContainsKey(strKey) Then
    
                               
                                Dim lv As ListViewItem = lst.Items.Add(location)
                                lv.SubItems.Add(name)
                                lv.SubItems.Add(type)
                                lv.SubItems.Add(uploaded)
                                lv.SubItems.Add(uploader)
                                lv.SubItems.Add("NEED BUTTON HERE")
    
    
                            End If
    
                        End While
                    End Using
                End Using
            End Using

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Button As Listview Subitem?

    The ListView control doesn't inherently support embedded controls. You might consider using a DataGridView instead, which does support embedded controls and supports buttons by default. The DataGridView has other advantages over the ListView too.

    If you must use a ListView for some specific reason then you should look at this.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Button As Listview Subitem?

    Could do it in easily in WPF

    sorry.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width