I have MainForm with TreeListView
from ObjectListView
library.
I want to input values in ValueColumn
(second column) with different Windows.Forms.Controls
components.
The TreeView
(name is jsonTreeView) normal displayed all values and it's types. It's based on my own class:
public class DataTreeNode
{
public string Name { get; set; }
public DataTreeNodeType Type { get; set; }
public string Value { get; set; }
public List<DataTreeNode> Children { get; set; }
}
First column is Name
, second is Value
and third is Type
. I want to create different input controls for values with different types (it saved in my class as string, but when convert to json it's parse like Type
value).
public partial class MainForm :
{
//...
ObjectListView.EditorRegistry.Register(typeof(string), delegate (Object model, OLVColumn column, Object value)
{
var node = model as DataTreeNode;
if(node == null) return new TextBox();
if (column.Index == 1)
{
switch (node.Type)
{
//...
case DataTreeNodeType.Boolean:
var cmbbBool = new ComboBox();
cmbbBool.Items.Add("False");
cmbbBool.Items.Add("True");
return cmbbBool;
case DataTreeNodeType.Str:
return new TextBox();
default:
return new TextBox();
}
}
return new TextBox();
}
//...
}
Documentation says:
Once the cell editor has been created, it is given the cell’s value via the controls Value property (if it has one and it is writable). If it doesn’t have a writable Value property, its Text property will be set with a text representation of the cells value.
When the user has finished editing the value in the cell, the new value will be written back into the model object (if possible). To get the modified value, the default processing tries to use the Value property again. It that doesn’t work, the Text property will be used instead.
But when i try to set any value with comboBox (this control HAS Text
property) return value is null
.
I tried to add not only strings in combobox, but custom and standart classes - nothing happens.
I found some solution (not so good, but solve the problem).
In source code of
ObjectListView
library i foundBooleanCellEditor
class. It's inherit fromComboBox
and present the value asBoolean
. I copy that code in my solution and change value frombool
tostring
.OLV Source code :
My source code:
I renamed class that it name more fit to code.