Last active
December 1, 2015 10:25
-
-
Save vereperrot/ed6acf916e26d3378299 to your computer and use it in GitHub Desktop.
http://objectlistview.sourceforge.net/cs/gettingStarted.html
http://stackoverflow.com/questions/19188245/objectlistview-how-to-show-child-list
http://stackoverflow.com/questions/7949887/how-to-add-a-new-item-into-objectlistview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Download the ObjectListView project | |
* Add the ObjectListView project to your project (right click on your solution; choose “Add...”, “Existing Project”, then choose the ObjectListView.csproj) | |
* In your project, add a reference to the ObjectListView project (right click on your project; choose “Add Reference...”, choose “Projects” tab; then double click on the ObjectListView project) | |
* there should now be a new section in your Toolbox, “ObjectListView Components”. In that section should be ObjectListView and its friends. (If you are using SharpDevelop, the section is called “Custom Components” and it appears at the bottom of the toolbox.) You can then drag an ObjectListView onto your window, and use it as you would a standard ListView control. | |
* add reference to your code | |
using System.Collections; | |
using BrightIdeasSoftware; | |
* sample code | |
// let the OLV know that a person node can expand | |
this.dataTreeListViewMain.CanExpandGetter = delegate(object rowObject) { | |
return (rowObject is Person); | |
}; | |
// retrieving the "things" from Person | |
this.dataTreeListViewMain.ChildrenGetter = delegate(object rowObject) { | |
Person person = rowObject as Person; | |
return person.Things; | |
}; | |
OLVColumn olvColumn1 = new OLVColumn(); | |
OLVColumn olvColumn2 = new OLVColumn(); | |
// column 1 shows name of person | |
olvColumn1.AspectGetter = delegate(object rowObject) { | |
if (rowObject is Person) { | |
return ((Person)rowObject).Name; | |
} else { | |
return ""; | |
} | |
}; | |
// column 2 shows thing information | |
olvColumn2.AspectGetter = delegate(object rowObject) { | |
if (rowObject is Thing) { | |
Thing thing = rowObject as Thing; | |
return thing.Name + ": " + thing.Description; | |
} else { | |
return ""; | |
} | |
}; | |
dataTreeListViewMain.Columns.Add(olvColumn1); | |
dataTreeListViewMain.Columns.Add(olvColumn2); | |
dataTreeListViewMain.Columns.Add(new OLVColumn("detail","Description")); | |
// add one root object and expand | |
dataTreeListViewMain.AddObject(new Person("Person 1")); | |
dataTreeListViewMain.ExpandAll(); | |
public class Person { | |
public string Name{get;set;} | |
public List<Thing> Things{get;set;} | |
public Person(string name) { | |
Name = name; | |
Things = new List<Thing>(); | |
Things.Add(new Thing("Thing 1", "Description 1")); | |
Things.Add(new Thing("Thing 2", "Description 2")); | |
} | |
} | |
public class Thing { | |
public string Name{get;set;} | |
public string Description{get;set;} | |
public Thing(string name, string desc) { | |
Name = name; | |
Description = desc; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment