问题
I'm trying to implement the doubleclick
function in an objectlistview
object.
According the developer, one should use ItemActivate
instead of MouseDoubleClick
.
So I came up with this:
private void treeListView_ItemActivate(object sender, EventArgs e)
{
try
{
ListView.SelectedIndexCollection col = treeListView.SelectedIndices;
MessageBox.Show(col[0].ToString());
}
catch (Exception e3)
{
globals.logfile.error(e3.ToString());
globals.logfile.flush();
}
finally
{
}
}
Which comes up with a value for each double clicked row. But how do I get the details from that row?
Here's the whole solution I'm now using:
private void treeListView_ItemActivate(object sender, EventArgs e)
{
try
{
var se = (StructureElement)treeListView.GetItem(treeListView.SelectedIndex).RowObject;
MessageBox.Show(se.id.ToString());
}
catch (Exception e3)
{
globals.logfile.error(e3.ToString());
globals.logfile.flush();
}
finally
{
}
}
回答1:
Which comes up with a value for each double clicked row. But how do I get the details from that row?
I think you have to access the RowObject
using the underlying OLVListItem
like this:
private void treeListView_ItemActivate(object sender, EventArgs e) {
var item = treeListView.GetItem(treeListView.SelectedIndex).RowObject;
}
回答2:
This is how I'm now getting the data out of the treelistview:
private void treeListView_ItemActivate(object sender, EventArgs e)
{
try
{
var se = (StructureElement)treeListView.GetItem(treeListView.SelectedIndex).RowObject;
MessageBox.Show(se.id.ToString());
}
catch (Exception e3)
{
globals.logfile.error(e3.ToString());
globals.logfile.flush();
}
finally
{
}
}
来源:https://stackoverflow.com/questions/31770863/objectlistview-doubleclick-explained