2016-12-25 6 views
1

TreeListViewObjectListView 라이브러리가있는 MainForm이 있습니다.ObjectListView 열의 C# combobox 값을 입력 할 때

다른 Windows.Forms.Controls 구성 요소로 ValueColumn (두 번째 열)에 값을 입력하고 싶습니다.

TreeView (이름은 jsonTreeView입니다.) normal은 모든 값과 유형을 표시합니다. 그것은 내 자신의 클래스를 기반으로 :

public class DataTreeNode 
{ 
    public string Name { get; set; } 
    public DataTreeNodeType Type { get; set; } 
    public string Value { get; set; } 
    public List<DataTreeNode> Children { get; set; } 
} 

첫 번째 열이 Name이고, 두 번째는 Value이며, 세 번째는 Type입니다. 서로 다른 유형의 값 (문자열로 클래스에 저장했지만, json으로 변환하면 Type 값처럼 구문 분석 됨)에 대해 다른 입력 컨트롤을 만들고 싶습니다. MainForm

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(); 
    } 
    //... 
} 

문서는 말한다 : 셀 에디터가 생성 된

되면 (있는하고 쓰기 가능한 경우),이 컨트롤의 값 속성을 통해 셀의 값이 부여됩니다. 쓰기 가능한 Value 속성이 없으면 Text 속성은 셀 값의 텍스트 표현으로 설정됩니다.

사용자가 셀의 값 편집을 마쳤 으면 가능한 경우 새 값이 모델 개체에 다시 기록됩니다. 수정 된 값을 가져 오려면 기본 처리에서 Value 속성을 다시 사용합니다. 작동하지 않으면 Text 속성이 대신 사용됩니다.

하지만 난으로 comboBox와 값 null 반환 값이 (Text 재산 HAS이 컨트롤)를 설정하려고 할 때. 콤보 상자의 문자열뿐만 아니라 사용자 지정 및 표준 클래스를 추가하려고했지만 아무 일도 일어나지 않습니다. enter image description here

enter image description here 어떻게이 트릭을 할 수 있습니까?

답변

2

몇 가지 해결책을 찾았습니다 (별로 좋지는 않지만 문제를 해결했습니다).

ObjectListView 라이브러리의 소스 코드에서 BooleanCellEditor 클래스를 찾았습니다. ComboBox에서 상속되며 값은 Boolean으로 표시됩니다. 해당 솔루션 코드를 복사하여 bool에서 string으로 변경하십시오.

OLV 소스 코드 :

internal class BooleanCellEditor : ComboBox 
{ 
    public BooleanCellEditor() { 
     this.DropDownStyle = ComboBoxStyle.DropDownList; 
     this.ValueMember = "Key"; 

     ArrayList values = new ArrayList(); 
     values.Add(new ComboBoxItem(false, "False")); 
     values.Add(new ComboBoxItem(true, "True")); 

     this.DataSource = values; 
    } 
} 

내 소스 코드 :

public class StringBooleanCellEditor : ComboBox 
{ 
    public StringBooleanCellEditor() 
    { 
     DropDownStyle = ComboBoxStyle.DropDownList; 
     ValueMember = "Key"; 

     var values = new ArrayList 
      { 
       new ComboBoxItem("False", "Ложь"), 
       new ComboBoxItem("True", "Истина") 
      }; 

     DataSource = values; 
    } 
} 

내가 그것을 코드에 더 적합한 이름을 클래스 이름.