locked
ListView Items RRS feed

  • Question

  • Hi.
    How I can insert same items into a ListView?
    Friday, May 1, 2009 6:27 PM

Answers

  • i mean on which line the exception is throwing?

    Put a breakpoint and singlestep you will get the exact location.

    Do you know what is D10?

    One more thing why are you assigning lst1.Text two times?
    Thanks, A.m.a.L | [Remember to click "mark as answered" when you get a correct reply to your question]
    Friday, May 1, 2009 8:30 PM

All replies

  • ListView1.Items.Add("1");
    ListView1.Items.Add("1");
    ListView1.Items.Add("1");
    ListView1.Items.Add("1");
    Thanks, A.m.a.L | [Remember to click "mark as answered" when you get a correct reply to your question]
    • Proposed as answer by JohnGrove Friday, May 1, 2009 6:56 PM
    Friday, May 1, 2009 6:35 PM
  • Short answer: ListView.Items.Add()

    Longer answer:

    ListView.Items is a property that returns a thing of type ListViewItemCollection.

    A ListViewItemcollection encapsulates the collection of items contained by the ListView. It is by calling methods in this collection property that you add and remove items, rather than calling methods directly from ListView. I expect you were wondering where something like ListView.AddItem() was - most people do at first.

    Anyway, check out all the members of ListViewItemCollection and you'll see the sorts of things you can do.
    Friday, May 1, 2009 6:38 PM
  • Also check out the what Matt said: An example could be:

     ListViewItem entry = new ListViewItem("Stuff"); 
     entry.SubItems.Add("Testing");
     listView1.Items.Add(entry);

    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    Friday, May 1, 2009 6:59 PM
  • Please tell on which line you are getting the exception
    Thanks, A.m.a.L | [Remember to click "mark as answered" when you get a correct reply to your question]
    Friday, May 1, 2009 8:22 PM
  • i mean on which line the exception is throwing?

    Put a breakpoint and singlestep you will get the exact location.

    Do you know what is D10?

    One more thing why are you assigning lst1.Text two times?
    Thanks, A.m.a.L | [Remember to click "mark as answered" when you get a correct reply to your question]
    Friday, May 1, 2009 8:30 PM
  • Thank you A.m.a.L .
    I found answer, I was use this code:

    ====>ListViewItem lst1 = new ListViewItem();
                DataSet ds = new DataSet();
                ds.ReadXml(ProjectPath.Remove(ProjectPath.Length - 4, 4) + ".xim");
                dataGridView1.DataSource = ds.Tables[0];

                int i = 0;
                int rows = ds.Tables[0].Rows.Count;
                for (i = 0; i < rows; i++)
                {
                   
                    lst1.Text = ds.Tables[0].Rows[i]["brcid"].ToString().Trim();
                    lst1.Text = ds.Tables[0].Rows[i]["brcid"].ToString().Trim();
                    lst1.SubItems.Add(ds.Tables[0].Rows[i]["story"].ToString().Trim());
                    lst1.SubItems.Add(ds.Tables[0].Rows[i]["combo"].ToString().Trim());
                    lst1.SubItems.Add(ds.Tables[0].Rows[i]["forcep"].ToString().Trim());
                    lst1.SubItems.Add(ds.Tables[0].Rows[i]["forcen"].ToString().Trim());
                    lst1.SubItems.Add(ds.Tables[0].Rows[i]["lenght"].ToString().Trim());
                    lst1.ImageIndex = 0;
                    listView1.Items.Add(lst1);
                }


    and now, I use this code:


    <==== //ListViewItem lst1 = new ListViewItem();
    ||          DataSet ds = new DataSet();
    ||          ds.ReadXml(ProjectPath.Remove(ProjectPath.Length - 4, 4) + ".xim");
    ||          dataGridView1.DataSource = ds.Tables[0];
    ||
    ||          int i = 0;
    ||          int rows = ds.Tables[0].Rows.Count;
    ||          for (i = 0; i < rows; i++)
    ||          {
    =====>   ListViewItem lst1 = new ListViewItem();
                    lst1.Text = ds.Tables[0].Rows[i]["brcid"].ToString().Trim();
                    lst1.Text = ds.Tables[0].Rows[i]["brcid"].ToString().Trim();
                    lst1.SubItems.Add(ds.Tables[0].Rows[i]["story"].ToString().Trim());
                    lst1.SubItems.Add(ds.Tables[0].Rows[i]["combo"].ToString().Trim());
                    lst1.SubItems.Add(ds.Tables[0].Rows[i]["forcep"].ToString().Trim());
                    lst1.SubItems.Add(ds.Tables[0].Rows[i]["forcen"].ToString().Trim());
                    lst1.SubItems.Add(ds.Tables[0].Rows[i]["lenght"].ToString().Trim());
                    lst1.ImageIndex = 0;
                    listView1.Items.Add(lst1);
                }
    Friday, May 1, 2009 8:34 PM
  • Nice to hear that :)
    Thanks, A.m.a.L | [Remember to click "mark as answered" when you get a correct reply to your question]
    Friday, May 1, 2009 8:35 PM
  • D10 is one of the values that i try to insert.
    I dont know any better methods, if it's possible, tell me more.

    Thanks.
    Friday, May 1, 2009 8:38 PM
  • No problem with the existing code. Go ahead brother :)
    Thanks, A.m.a.L | [Remember to click "mark as answered" when you get a correct reply to your question]
    Friday, May 1, 2009 8:41 PM