【问题标题】:ObjectListView get value of a specific columnObjectListView 获取特定列的值
【发布时间】:2016-03-18 23:47:01
【问题描述】:

我用的是C#和ObjectListView,需要获取具体点击的行列的值。

示例:获取点击的行第 3 列的值。

如何通过 CellClick 做到这一点?

private void treeListView1_CellClick(object sender, CellClickEventArgs e)
{
   ???
}

【问题讨论】:

标签: c# visual-studio treeview objectlistview


【解决方案1】:

我只想获取第 3 列的值,无论我在哪里点击。

private void objectListView1_CellClick(object sender, CellClickEventArgs e) {
    // check if it is the column of interest
    if (e.Column == olvColumn3) {
        // method 1: just get the value from the objectListView1 cell, 
        // this potentially requires casting ModelValue to the correct type which can be error prone if the type changes
        object value = e.SubItem.ModelValue;

        // method 2: since you "know" what property of your underlying model is displayed in column 3,
        // you should retrieve it directly from the model object
        MyModel modelObject = (MyModel)e.Model;
        string value2 = modelObject.ValueThatBelongsToColumn3;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多