Please help. Im having trouble displaying the checkbox's text in the listview form. It only display's the text of the 1st checkbox.


I cant seem to display the remaining checkbox.text. It only display's the 1st checkbox in my ListView form. I have another form for ListView.vb


Here is the code:

Public Class Abdominal
Private Sub selectAll_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles selectAll.CheckedChanged
If selectAll.Checked = True Then
crunches.Checked = True
legRaises.Checked = True
reverseCrunches.Checked = True
overheadLegRaise.Checked = True
declineBenchSitups.Checked = True
pullDownCableCrunches.Checked = True
End If
End Sub

Private Sub sumbit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sumbit.Click
Dim i As Integer
Dim newItem As New ListViewItem(i + 1) '// add text Item
newItem.SubItems.Add(crunches.Text)
newItem.SubItems.Add(legRaises.Text)
newItem.SubItems.Add(reverseCrunches.Text)
newItem.SubItems.Add(overheadLegRaise.Text)
newItem.SubItems.Add(declineBenchSitups.Text)
newItem.SubItems.Add(pullDownCableCrunches.Text)
ListView.ListView1.Items.Add(newItem)

ListView.Show()
End Sub
End Class

Recommended Answers

All 7 Replies

See if this helps since you probably do not have columns added to your ListView.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With ListView1
            .Columns.Add("Column 1", 100) : .Columns.Add("Column 2", 100) : .Columns.Add("Column 3", 100) '// add Columns, "100" is column.Width.
            .View = View.Details '// display the Columns.
            .FullRowSelect = True '// highlight entire row when item clicked.
        End With
    End Sub

Sir I already have 2 columns in my listview. But it just display's crunches.text. It doesn't display the remaining 5 checkbox.text.

Add more Columns to your ListView, since Column 1 only displays a # and Column 2 will only display your first CheckBox.Text.

Sir is it possible that only if the checkbox is checked that's the time when the values display in the listview?

If crunches.Checked Then newItem.SubItems.Add(crunches.Text)
        If legRaises.Checked Then newItem.SubItems.Add(legRaises.Text)
        '// etc...

Sir,

Its adding by column. Can it be added by rows?

Dim i As Integer = 0
        Dim newItem As New ListViewItem
        With newItem
            If crunches.Checked Then '// since first item, no need to declare as New item.
                .Text = (i + 1).ToString  '// add text Item
                newItem.SubItems.Add(crunches.Text)
                ListView.ListView1.Items.Add(newItem)
            End If
            If legRaises.Checked Then
                newItem = New ListViewItem '// declare as New item.
                .Text = (i + 1).ToString  '// add text Item
                .SubItems.Add(legRaises.Text)
                ListView.ListView1.Items.Add(newItem)
            End If
            '// etc...
        End With
commented: nice as always +8
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.