我想使用listview填充數據,然後使用鼠標點擊事件來填充一些文本框與數據。我擡頭一看MSDN中的例子:使用鼠標點擊事件獲取ListViewItem文本
ListViewItem theClickedOne = listView1.GetItemAt(e.X, e.Y);
ListViewItem theClickedtwo = listView1.FocusedItem;
if (theClickedOne != null)
{
MessageBox.Show(theClickedtwo.ToString());
//do your thing here.
//there is a reference to the listview item we clicked on
//in our theClickedOne variable.
}
,但我不能想想辦法,以區分我用,因爲我在程序的拳頭列是相同的listviewitems使用它,它只會給我是一個字符串與它的名字(第一列)。我想有一些類似於下一個例子,但對於樹視圖。
void treeView1_NodeMouseClick(Object sender, TreeNodeMouseClickEventArgs e)
{
MessageBox.Show(e.Node.Text);
}
當談到區分UI元素時,我通常會設置元素的Tag屬性。仔細查看一下。 – helb 2014-12-04 07:51:13
「我想要類似於下一個示例,但是對於treeview。」 - 什麼?你想用ListView控件還是TreeView來做到這一點?直到最後一條語句爲止,大部分帖子似乎都說'ListView'。 – 2014-12-04 07:56:02
我知道,在我的代碼中,我也使用treeview和mouseclick事件,並且我更容易得到如何使用它並識別strings.I認爲listview將是相同的,它是不同的。 – user3365107 2014-12-04 08:45:43