views:

184

answers:

2

Is there a way to copy the text of the selected subitem from a ListView in .NET Winforms?

+2  A: 

Each item inside of a ListView control is represented by a ListViewItem. The ListViewItem has a property called SubItems which starts from the very first column of data in the ListView control.

To copy data from a column, get the selected ListViewItem and reference the Text property available from the SubItems property.

For example,

int theSelectedIndex = 0; // this should be the index of your selected item in the list
int theSubItemIndex = 0; // this should be the index of the subitem whose text you want to copy

ListViewItem lvItem = listView1.SelectedItems[theSelectedIndex];
string text = lvItem.SubItems[theSubItemIndex].Text;
Mike J
A: 

Unless I'm really missing something fundamental, you can't select a subitem. You can select the subitem in the first column or you can set the FullRowSelect property to True. Neither helps you to determine what subitem the user might be interested in, there's no way to guess what to copy to the clipboard.

Use DataGridView to work around that.

Hans Passant