Thread: another listview question

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    18

    another listview question

    i have a listview with 4 columns, when i select a line and click a button, i want to add it to a listbox....but i dont know how to get the text from the selected line. ive tried listview.SelectedItems.ToString() and listview.SelectedIndices.ToString()
    both of them come up with some ListView.Selected...+object or something wierd like that
    thanks

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Both of them are Collections of Items, that's why they are named with a plural 's'. Use foreach.

    foreach( ListViewItem item in yourListView.SelectedItems )
    {
    ListBox.Add( item.Text );
    }

    Depending on your comlumns, you may have to add another foreach here for getting all SubItems of your item to add all their text together.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Troubles with ListView and Toolbar
    By cornholio in forum Windows Programming
    Replies: 8
    Last Post: 11-14-2005, 01:26 AM
  2. Listview with c/c++
    By X PaYnE X in forum Windows Programming
    Replies: 8
    Last Post: 03-20-2005, 11:29 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. listview question
    By datainjector in forum C# Programming
    Replies: 4
    Last Post: 07-08-2003, 05:06 PM
  5. Listview??
    By SuperNewbie in forum C# Programming
    Replies: 4
    Last Post: 02-13-2003, 03:34 AM