Search code examples
c#objectlistview

Objectlistview doubleclick explained


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

Solution

  • 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;     
    }