I'm using ObjectListView in winforms application, I used full row select option, when ever I'll select a row I want details of that row object(each row created like a object) This is the way i created so far..
class Node
{
public string Name { get; private set; }
public string StartTime { get; private set; }
public string EndTime { get; private set; }
public string tag;
public List<Node> Children { get; private set; }
public Node(string name, string col1, string col2, string col3, string col4)
{
this.Name = name;
this.StartTime = col1;
this.EndTime = col2;
this.Children = new List<Node>();
}
}
public MainForm()
{
treeListView = new BrightIdeasSoftware.TreeListView();
Result.Controls.Add(treeListView);
treeListView.CanExpandGetter = x => (x as Node).Children.Count > 0;
// set the delegate that the tree uses to know the children of a node
treeListView.ChildrenGetter = x => (x as Node).Children;
// create the tree columns and set the delegates to print the desired object proerty
var nameCol = new BrightIdeasSoftware.OLVColumn("Name", "Name");
nameCol.AspectGetter = x => (x as Node).Name;
var col1 = new BrightIdeasSoftware.OLVColumn("StartTime", "StartTime");
col1.AspectGetter = x => (x as Node).StartTime;
var col2 = new BrightIdeasSoftware.OLVColumn("EndTime", "EndTime");
col2.AspectGetter = x => (x as Node).EndTime;
// add the columns to the tree
treeListView.Columns.Add(nameCol);
treeListView.Columns.Add(col1);
treeListView.Columns.Add(col2);
treeListView.FullRowSelect = true;
var parent1 = new Node("PARENT1", "-", "-", "-");
parent1.Children.Add(new Node("CHILD_1_1", "A", "X", "1"));
parent1.Children.Add(new Node("CHILD_1_2", "A", "Y", "2"));
parent1.Children.Add(new Node("CHILD_1_3", "A", "Z", "3"));
var parent2 = new Node("PARENT2", "-", "-", "-");
parent2.Children.Add(new Node("CHILD_2_1", "B", "W", "7"));
parent2.Children.Add(new Node("CHILD_2_2", "B", "Z", "8"));
parent2.Children.Add(new Node("CHILD_2_3", "B", "J", "9"));
var parent3 = new Node("PARENT3", "-", "-", "-");
parent3.Children.Add(new Node("CHILD_3_1", "C", "R", "10"));
parent3.Children.Add(new Node("CHILD_3_2", "C", "T", "12"));
data = new List<Node> { parent1, parent2, parent3 };
treeListView.Roots = data;
treeListView.CellClick += (sender2, e2) => selectedRow(sender2, e2);
}
private void selectedRow(object sender2, CellClickEventArgs e2)
{
object v2 = treeListView.SelectedObject();
//here i want columns data of selected row, but i can't get using v2 object
}
}
I don't know whether i'm using correct function "CellClick()" or not
Assuming that you have selected an object, then ObjectListView provides the following:
You can then check that the object is the right type and cast it. An example is below:
if (objectListView1.SelectedItems.Count > 0)
{
MyObject obj = objectListView1.SelectedObject as MyObject;
if (obj != null)
{
//Work on your object here.
}
}
Edit: Since I wrote this you added your code to show that you are using TreeListVew, so the concept is similar but I don't know if it is exactly the same code.