Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ListView Control

ListView Control

Scheduled Pinned Locked Moved C#
questiondatabase
5 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Orion Buttigieg
    wrote on last edited by
    #1

    hello, i'm trying to do 2 things with this control. the first is add a value to a sub-column of a row(or officially stated, the sub item to the item). the catch is, i can add the item to the row if its Selected. such as: listView.Items[listView.SelectedItems[0].Index].SubItems[1].Text = this.textBox_Value.Text; if i try to add the value without a row being selected it crashes the control. if i try: item.SubItems.Add(this.textBox_Value.Text); this.listView_Parameters.Items[0] = items; it just adds it to the second column of a new row. so how do i add a value to a particular row/sub-column without selecting that row? the second, i've also been trying to show a row as being Selected with the blue line. ideally i'd like to put a value in the control and show it as if its been selected. any advice would be greatly appreciated. i'm probably missing something obvious...:wtf: thank you, Orion

    B 1 Reply Last reply
    0
    • O Orion Buttigieg

      hello, i'm trying to do 2 things with this control. the first is add a value to a sub-column of a row(or officially stated, the sub item to the item). the catch is, i can add the item to the row if its Selected. such as: listView.Items[listView.SelectedItems[0].Index].SubItems[1].Text = this.textBox_Value.Text; if i try to add the value without a row being selected it crashes the control. if i try: item.SubItems.Add(this.textBox_Value.Text); this.listView_Parameters.Items[0] = items; it just adds it to the second column of a new row. so how do i add a value to a particular row/sub-column without selecting that row? the second, i've also been trying to show a row as being Selected with the blue line. ideally i'd like to put a value in the control and show it as if its been selected. any advice would be greatly appreciated. i'm probably missing something obvious...:wtf: thank you, Orion

      B Offline
      B Offline
      Brandon Parker
      wrote on last edited by
      #2

      look at your code. If you use SelectedItems property to get an index value for your listview, and no item is selected there wont be a value in SelectedItems[0], thats why it crashes. // Add a new item and at subcolumn int index = Items.Count; ListViewItem item = new ListViewItem("Column Text,index) item.SubItems.Add("Subcolumn Text"); Items.Add(item); // Add only a subitem to an existing item listView.Items[index].SubItems.Add("subcolumn Text"); you can show a blue line by first adding the item to the row then use the controls SelectedItem property to select the index of the new item. You might also want to make sure that fullrowselect is set to true. Brandon Parker

      O 1 Reply Last reply
      0
      • B Brandon Parker

        look at your code. If you use SelectedItems property to get an index value for your listview, and no item is selected there wont be a value in SelectedItems[0], thats why it crashes. // Add a new item and at subcolumn int index = Items.Count; ListViewItem item = new ListViewItem("Column Text,index) item.SubItems.Add("Subcolumn Text"); Items.Add(item); // Add only a subitem to an existing item listView.Items[index].SubItems.Add("subcolumn Text"); you can show a blue line by first adding the item to the row then use the controls SelectedItem property to select the index of the new item. You might also want to make sure that fullrowselect is set to true. Brandon Parker

        O Offline
        O Offline
        Orion Buttigieg
        wrote on last edited by
        #3

        thanks Brandon, actually a few minutes after i posted it i did get the first part. i did it a little different though. listView.Items[0].SubItems[1].Text = this.textBox_Value.Text; as for showing the blue line, i want to show it before any sub item has been added. to let the user know the first row has been auto selected. i've got the FullRowSelect prop set to true, no problem. if i do this.listview.SelectedItems[0] = true;//it complains Orion

        B 1 Reply Last reply
        0
        • O Orion Buttigieg

          thanks Brandon, actually a few minutes after i posted it i did get the first part. i did it a little different though. listView.Items[0].SubItems[1].Text = this.textBox_Value.Text; as for showing the blue line, i want to show it before any sub item has been added. to let the user know the first row has been auto selected. i've got the FullRowSelect prop set to true, no problem. if i do this.listview.SelectedItems[0] = true;//it complains Orion

          B Offline
          B Offline
          Brandon Parker
          wrote on last edited by
          #4

          try this instead. I havent tried it so im not sure it will work,so let me know. Also remember, if you use the SelectedItems Property and no item is selected then it will be null. so it will complain. this.listView.Items[0].Selected = true;

          O 1 Reply Last reply
          0
          • B Brandon Parker

            try this instead. I havent tried it so im not sure it will work,so let me know. Also remember, if you use the SelectedItems Property and no item is selected then it will be null. so it will complain. this.listView.Items[0].Selected = true;

            O Offline
            O Offline
            Orion Buttigieg
            wrote on last edited by
            #5

            it sort of works, but now the value i'm adding to the sub item/second column doesn't go in... back to the drawing board and thanks:) Orion

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups