【问题标题】:Get the position of a ListView item that was just created?获取刚刚创建的 ListView 项的位置?
【发布时间】:2017-01-04 15:48:54
【问题描述】:

在我的 winform 中,我像这样在列表视图中创建一个项目;

ListViewItem item = listView1.Items.Add("an item");

我怎样才能得到它的 position 索引?我尝试了以下方法;

int position = item.Position;
int position = item.SelectedIndices[0];

但两者都不起作用。

我会使用listView1.SelectedIndices[0];,但新创建的项目没有被选中,所以这也不起作用。

编辑:通过位置,我的意思是项目的索引,而不是它的坐标。为混乱道歉!

【问题讨论】:

    标签: c# winforms listview int


    【解决方案1】:

    Add 方法都返回一个ListViewItem 对象。 ListViewItem 对象有一个 Index 属性,它将返回 ListView 控件中项的从零开始的索引。

    Position 方法完全不同。它返回 ListViewItem 左上角的坐标。这些坐标是相对于 ListView 控件的。

    【讨论】:

    • 所以我应该使用item.Index ?
    • 如果你想要索引,是的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多