C# ObjectListView获取特定列的值
我使用的是C#和ObjectListView,需要获取特定单击位置的行和列的值 示例:获取单击行第3列的值 我如何通过CellClick做到这一点C# ObjectListView获取特定列的值,c#,visual-studio,treeview,objectlistview,C#,Visual Studio,Treeview,Objectlistview,我使用的是C#和ObjectListView,需要获取特定单击位置的行和列的值 示例:获取单击行第3列的值 我如何通过CellClick做到这一点 private void treeListView1_CellClick(object sender, CellClickEventArgs e) { ??? } 我只想得到第3列的值,不管我在哪里单击 这看起来是同一个问题:我只想得到第3列的值,不管我在哪里单击。怎么样? private void objectListView1_Cell
private void treeListView1_CellClick(object sender, CellClickEventArgs e)
{
???
}
我只想得到第3列的值,不管我在哪里单击
这看起来是同一个问题:我只想得到第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;
}
}