Click here to Skip to main content
16,012,223 members
Home / Discussions / C#
   

C#

 
GeneralRe: "The file 'APSDatabase.dll' cannot be copied to the run directory." Pin
Heath Stewart21-May-04 9:18
protectorHeath Stewart21-May-04 9:18 
GeneralRe: "The file 'APSDatabase.dll' cannot be copied to the run directory." Pin
Steve Schaneville21-May-04 10:01
professionalSteve Schaneville21-May-04 10:01 
GeneralUnsubscribing from an event Pin
ABean21-May-04 7:26
ABean21-May-04 7:26 
GeneralRe: Unsubscribing from an event Pin
Charlie Williams21-May-04 7:56
Charlie Williams21-May-04 7:56 
GeneralDataTable Pin
IamADotNetGuy21-May-04 7:26
IamADotNetGuy21-May-04 7:26 
GeneralRe: DataTable Pin
Heath Stewart21-May-04 8:53
protectorHeath Stewart21-May-04 8:53 
GeneralListView on select Pin
Adam Hable21-May-04 6:44
Adam Hable21-May-04 6:44 
GeneralRe: ListView on select Pin
Heath Stewart21-May-04 6:57
protectorHeath Stewart21-May-04 6:57 
Get the index of the ListViewItem and get the sub item:
private void listView1_SelectedIndexChanged(object sender,
  EventArgs e)
{
  int index = listView1.SelectedIndex;
  if (index >= 0)
  {
    ListViewItem item = listView1.Items[index];
    // Get the second column of text.
    string value = item.SubItems[1]; // The first column is index 0.
    MessageBox.Show(value);
  }
}
If you actually want the column that the user clicked on, you need to perform a hit text:
private int GetColumnIndex()
{
  Point p = listView1.PointToClient(
    new Point(MousePosition.X, MousePosition.Y));
  int width = 0;
  foreach (ColumnHeader header in listView1.Columns)
  {
    width += header.Width;
    if (p.X < width) return header.Index;
  }
  return -1;
}
You could call this method to get the column index (be mindful that it could be -1) and use that as the index into ListViewItem.SubItems.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: ListView on select Pin
Adam Hable21-May-04 9:10
Adam Hable21-May-04 9:10 
GeneralRe: ListView on select Pin
Heath Stewart21-May-04 9:18
protectorHeath Stewart21-May-04 9:18 
GeneralRe: ListView on select Pin
Adam Hable21-May-04 9:21
Adam Hable21-May-04 9:21 
GeneralRe: ListView on select Pin
Heath Stewart21-May-04 9:35
protectorHeath Stewart21-May-04 9:35 
GeneralRe: ListView on select Pin
Adam Hable21-May-04 9:55
Adam Hable21-May-04 9:55 
GeneralRe: ListView on select Pin
Heath Stewart21-May-04 9:57
protectorHeath Stewart21-May-04 9:57 
GeneralRe: ListView on select Pin
valikac21-May-04 7:08
valikac21-May-04 7:08 
GeneralRe: ListView on select Pin
Heath Stewart21-May-04 9:20
protectorHeath Stewart21-May-04 9:20 
GeneralOne about Remoting Pin
Diego F.21-May-04 6:22
Diego F.21-May-04 6:22 
GeneralRe: One about Remoting Pin
Heath Stewart21-May-04 6:46
protectorHeath Stewart21-May-04 6:46 
GeneralRe: One about Remoting Pin
Diego F.21-May-04 7:56
Diego F.21-May-04 7:56 
GeneralRe: One about Remoting Pin
Heath Stewart21-May-04 8:48
protectorHeath Stewart21-May-04 8:48 
GeneralRe: One about Remoting Pin
Diego F.22-May-04 4:06
Diego F.22-May-04 4:06 
GeneralRe: One about Remoting Pin
Heath Stewart22-May-04 4:11
protectorHeath Stewart22-May-04 4:11 
GeneralRe: One about Remoting Pin
Diego F.24-May-04 5:42
Diego F.24-May-04 5:42 
GeneralRe: One about Remoting Pin
Heath Stewart24-May-04 5:46
protectorHeath Stewart24-May-04 5:46 
GeneralRe: One about Remoting Pin
Diego F.25-May-04 6:05
Diego F.25-May-04 6:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.