Search code examples
objectlistview

Get TreeListView cell value programmatically in ObjectListView


How can I programmatically obtain the value of a cell in OLV's treeListView using the row and column index?

treeListView.GetItem(0).GetSubItemAt(6,e.rowIndex).Text 

for example does not appear to work, it just gives me the string value of the first cell of the first row. Also I do not understand the answer here:

ObjectListView: select subitem programmatically


Solution

  • Working with the sub items is not recommended and you should never have to access them when using the ObjectListView/TreeListView controls.

    You should retrieve the model object of the required row instead, and then access the property that is related to the column/cell in question.

    You can retrieve the model with

    MyModel model = objectListView1.GetModelObject(rowIndex) as MyModel
    

    where MyModel is your underlying model class.