How can I set the ListView Item no to show

Here is my code:
visual basic code:
Do While MyDataReader.Read Dim myItems = lvSelected.Items.Add(MyDataReader("PanelCode".ToString)) With myItems .SubItems.Add(MyDataReader("ExamName".ToString)) .subitems.add(MyDataReader("Price".ToString)) .subitems.add("1") End With Loop


What I want to achieve is that when "PanelCode" field in my database had a value, I would not display it in the lvselected(listview), just the subitems.I had tried using this code:
visual basic code:
If MyDataReader("PanelCode".ToString)<>"" then MyDataReader("PanelCode".ToString)="" End If

but it was giving me an exception stating that "Item" is ReadOnly.How can I possibly do this thanks...


Answer this question

How can I set the ListView Item no to show

  • chicagoclone

    I don't quite get it, you want to make the item.Text property blank when the PanelCode field has a value. If it doesn't have a value, it would be blank too. So always use:
    Dim myItems = lvSelected.Items.Add("")

    Other than that, your use to ToString looks wrong. I assume you need MyDataReader("fieldname").ToString


  • lee anthony

    It seems to me that, according to your code, you're setting MyDataReader, which could be readonly, to empty string. You could try to set your actual display (ListView) to empty string instead. Assuming ListView is not set to ReadOnly, you should be able to set ListView1.Items(i).Text = ""

    Yun


  • st8floorsup

    First problem is your use of ToString...It should be outide of the parameter...such as

    Dim myItems = lvSelected.Items.Add(MyDataReader("PanelCode").ToString)
     

    Then use String.IsNullOrEmpty for your comparison:

    If Not String.IsNullOrEmpty(MyDataReader("PanelCode").ToString) Then



  • How can I set the ListView Item no to show