Click here to Skip to main content
15,037,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have added radio buttons dynamically to the listview and it is exceeding the size of listview provided so i need to add scroll bar to listview and i have to show all elements by scrolling, how i can do that???

What I have tried:

listview1.scrollable=true //but it is not displaying scroll bar
Posted
Updated 20-Feb-17 19:28pm

1 solution

You need to Set:
VB
Listview1.Scrollable = true
Listview1.View = View.Details

This will only work correctly if you have added some columns in your Listview1, So add a dummy column. like:
VB
Dim header As New ColumnHeader()
header.Text = ""
header.Name = "col1"
listView1.Columns.Add(header)

UPDATE: Added working sample
VB
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim header As New ColumnHeader()
        header.Text = "test 1"
        header.Name = "col1"
        ListView1.Columns.Add(header)

        ListView1.Scrollable = True
        ListView1.View = View.Details

        For i = 1 To 200
            ListView1.Items.Add(String.Format("List {0}", i))
        Next

    End Sub
End Class
   
v2
Comments
Member 13007431 21-Feb-17 3:09am
   
but its not coming..
Graeme_Grant 21-Feb-17 3:28am
   
I built a working sample from scratch and updated my solution with it. Do the same before applying to your own.
Member 13007431 21-Feb-17 3:48am
   
ya your code is working fine but when i add the same code to my project its not working, i have used radio buttons which are created dynamically and i have added those buttons to listview in that its not showing the scrollbar
Graeme_Grant 21-Feb-17 3:50am
   
This indicates that there is a problem with your code, so time to start debugging. Slowly cut back (comment out) your code until it works. Then you will better be able to find what needs correcting.
Member 13007431 21-Feb-17 4:08am
   
Public Sub display1()

For Each pList As product In productArrayList
Dim sr As String = " "
If hset.Contains(pList.ProductName) = False Then
hset.Add(pList.ProductName)

Dim l As Label = New Label()
l.Text = pList.ProductName
l.Location = New Point(x, y)
l.Name = pList.ProductName & pList.ProductVersion

x = x + 3
y = y + 20
Form1.Controls.Add(l)
Printradio(pList)
Else
Printradio(pList)
End If

Dim regList As List(Of KeyValuePair(Of String, Dictionary(Of String, String)))
regList = pList.ProductRegInfo

For Each regKeyValuePair As KeyValuePair(Of String, Dictionary(Of String, String)) In regList
sr = sr & (pList.ProductName & pList.ProductVersion & regKeyValuePair.Key)
Dim regKeyValuePairD As Dictionary(Of String, String)
regKeyValuePairD = regKeyValuePair.Value
For Each prd In regKeyValuePairD
sr = sr & (prd.Key() & prd.Value())
Next
Next
' MessageBox.Show(sr)
Next

End Sub
Public Sub Printradio(ByVal plist)
Dim rad1 As RadioButton = New RadioButton()
rad1.Text = plist.ProductVersion & "," & plist.ProductName
rad1.Location = New Point(x, y)
y = y + 30
Form1.Controls.Add(rad1)

End Sub
///this is the function where i will add radio buttons and label to form ....
so where i have to add above code????
Graeme_Grant 21-Feb-17 4:09am
   
I have given you a working solution, now it is up to you to fix your code.
Member 13007431 21-Feb-17 4:16am
   
Okay tnq
Member 13007431 21-Feb-17 4:09am
   
i want to show above added radio buttons and labels in listview having scroll bar, how i can do it???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900