Click here to Skip to main content
15,904,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using visual studio 2012 express. I have a form with a menu strip, 2 radiobuttons, and a listview. What I want to happen is when radiobutton2 is checked, the listview to populate with some numbers and a type (string). I have done something similar before in another project but it is not working in this project. I have read about what settings need to be set in a listview for it to work and I set them (see all of the links). I prefer to have the "Card #" variable shown first, then the type. If I try to run the code now, I only get 1 column filled in, the other one is always blank.

What I have tried:

This is the code that DON'T work!

<pre>
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
        Dim CardType As String = Nothing
        Dim tmpStr As String = Nothing

        RadioButton2.Font = IIf(RadioButton2.Checked = True, New Font(RadioButton2.Font, FontStyle.Bold), New Font(RadioButton2.Font, FontStyle.Regular))

        If RadioButton2.Checked = True Then
            ComboBox1.Items.Clear()
            ComboBox1.Text = Nothing
            ComboBox1.Enabled = False
            ListView1.Enabled = True

            For x As Integer = 1 To NumberOfCards
                tmpStr = Trim(Mid(MyCard(x, 1, 1), 5, 1))
                CardType = Microsoft.VisualBasic.Switch(tmpStr = "D", "Deleted", tmpStr = "H", "Hard", tmpStr = "S", "Special")
                If tmpStr <> "D" Then
                    Dim wrditem As New ListViewItem
                    wrditem.Text = Str(x)
                    wrditem.SubItems.Add(CardType)
                    ListView1.Items.Add(wrditem.Text)
                End If
            Next
        End If

    End Sub


This is what I get when I run the code:
Running Form.jpg - Google Drive[^]
Posted
Updated 13-Jan-19 4:44am
v5
Comments
Richard MacCutchan 13-Jan-19 9:47am    
It would make more sense to show the actual code that has the problem, and expalain exactly what is going wrong. Especially as all of your URL's are invalid (they all point to this page).

1 solution

VB
ListView1.Items.Add(wrditem.Text)

You are adding only the text of the new ListViewItem, instead of the entire item. It should be:
VB
ListView1.Items.Add(wrditem)
 
Share this answer
 
Comments
Maciej Los 14-Jan-19 6:53am    
Hawk eye!
Richard MacCutchan 14-Jan-19 6:55am    
Ha ha; I am the one who usually misses things like that.
Maciej Los 14-Jan-19 7:00am    
Me too ;)

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