Objectlistview doubleclick explained

2019-06-05 09:54发布

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
        {
        }
    }

2条回答
The star\"
2楼-- · 2019-06-05 10:30

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;     
}
查看更多
混吃等死
3楼-- · 2019-06-05 10:40

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
    {
    }
}
查看更多
登录 后发表回答