2015-04-05 65 views
-1

我的列表視圖將顯示我的數據庫中的3列。列表查看雙擊

 ID   Username  Email 
     ------------------------------------ 
     234   Joe   [email protected] 
     235   Jeff   [email protected] 
     246   Jerry  [email protected] 

當我雙擊行,我也想從選定的行中獲得'用戶名'和'電子郵件'的值。

我有全行選擇設置爲true,但它只會顯示ID值。

private void listView1_MouseDoubleClick(object sender, MouseEventArgs e) 
    { 
     ListViewHitTestInfo hit = listView1.HitTest(e.Location); 
     if (hit.Item != null) 
     { 
      MessageBox.Show(hit.Item.Text); 
     }; 
+2

hit.Item.Text + 「」 hit.Item.SubItems [1]。文本+ 「」 .. – TaW 2015-04-05 19:38:02

回答

0

我可以證實TaW的答案是正確的。

正確的代碼...

 ListViewHitTestInfo hit = listView1.HitTest(e.Location); 
     if (hit.Item != null) 
     { 
     MessageBox.Show(hit.Item.Text + " " + hit.Item.SubItems[1].Text + " " + hit.Item.SubItems[2].Text + " ");  
     };