none
Listview checkbox items VB.NET

    Question

  • Good Morning I have a question about listview and checkbox well I have a Listview with checkboxes and in my listview I have to columns for example column 1 is ID and column 2 descrip, I have in a string something record, I need to check the boxes that I have record in my string for example if in my string I have recorded dog,cat,bird in the listview the checkbox check with the item that i have recorded in my string  I don't know if I explain good.Thanks
    Monday, March 21, 2011 2:40 PM

Answers

  • Hi manuel2011,

    I think the following codes is what you want:

    string s = "dog,cat,bird";
    this.listView1.Items.Add("id1").SubItems.Add("dog");
    this.listView1.Items.Add("id2").SubItems.Add("cat");
    this.listView1.Items.Add("id3").SubItems.Add("bird");
    this.listView1.Items.Add("id4").SubItems.Add(".net");
    
    foreach(ListViewItem lvi in this.listView1.Items)
    {
      if (s.Contains(lvi.SubItems[1].Text))
      {
        lvi.Checked = true;
      }
    }
    

    Have a nice day!


    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 23, 2011 1:04 PM
    Moderator

All replies

  • Yep, this sounds a bit strange. it would be really go that you do try a bit harder, and do another explanation. Its almost impossible to figure out what you have stated.

    Ok, I have foreseen that you have a listView controls with checkBox column, and two additional columns (id and description).

    But from then on I have no clue what you are talkin about. Please, try ones again. Simple and clean. Easly.

    Mitja 

    Monday, March 21, 2011 3:39 PM
  • Hi manuel2011,

    I think the following codes is what you want:

    string s = "dog,cat,bird";
    this.listView1.Items.Add("id1").SubItems.Add("dog");
    this.listView1.Items.Add("id2").SubItems.Add("cat");
    this.listView1.Items.Add("id3").SubItems.Add("bird");
    this.listView1.Items.Add("id4").SubItems.Add(".net");
    
    foreach(ListViewItem lvi in this.listView1.Items)
    {
      if (s.Contains(lvi.SubItems[1].Text))
      {
        lvi.Checked = true;
      }
    }
    

    Have a nice day!


    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 23, 2011 1:04 PM
    Moderator