Objectlistview doubleclick explained

假装没事ソ 提交于 2019-12-08 08:47:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!