2009-08-03 6 views
2

내가 그의 초기 클래스 정의 ListView 컨트롤과 제네릭을 사용하고는 다음과 같습니다제네릭 ListView에 사용자 지정 컨트롤

partial class CustomListView 
{ 
    /// <summary> 
    /// Required designer variable. 
    /// </summary> 
    private System.ComponentModel.IContainer components = null; 

    /// <summary> 
    /// Clean up any resources being used. 
    /// </summary> 
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 
    //protected override void Dispose(bool disposing) 
    //{ 
    // if (disposing && (components != null)) 
    // { 
    //  components.Dispose(); 
    // } 
    // base.Dispose(disposing); 
    //} 

    #region Component Designer generated code 

    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor. 
    /// </summary> 
    private void InitializeComponent() 
    { 
     components = new System.ComponentModel.Container(); 
     // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
    } 

    #endregion 
} 

는 내가하고 싶은 것은 다음과 같습니다

namespace BaseControlLibrary 
{ 
    public partial class CustomListView<T> : System.Windows.Forms.ListView 
    { 
     // Custom fields, properties, methods go here 

     public CustomListView(List<T> data) 
     { 
      _columnInfo = new Dictionary<int, string>(); 
      _columnIndex = 0; 

      _lvwItemComparer = new ListViewItemComparer(); 
      this.ListViewItemSorter = _lvwItemComparer; 

      InitializeColumnNames(); 
      BindDataToListView(data); 

      this.Invalidate(); 
     } 
    } 
} 

내 디자이너 파일입니다 Windows 컨트롤 라이브러리를 만들고 성공적으로 수행했지만 도구 상자에 DLL을 추가 할 수없는 경우 문제가 발생합니다. 나는 왜 내가 이것을 할 수 없는지 정확히 알지 못합니다. 모든 Windows Forms 컨트롤이 도구 상자에 항목을 추가하는 데 필요한 IComponent 인터페이스를 구현한다고 생각했습니다. 클래스 정의의 일부로 유형 매개 변수가 있기 때문입니까?

+1

공개 매개 변수없는 생성자가 없을 수도 있습니까? – Zyphrax

답변

3

디자이너가 싫어 : 런타임시 작동하는 경우

에도 abstract베이스 클래스와

  • 일을

    • 제네릭, 당신은 아마가에 출근하지 않을거야 IDE. 죄송합니다. 아마도 Type 속성을 가진 비 - 제네릭 클래스를 고려해보십시오; 그

      이 BTW, CustomListView<T>CustomListView완전히 다른 클래스입니다 ... 당신이 할 수 있습니다 최고의 관하여이다. 수업은 2 가지가 아니라 1 가지가 있습니다.

  • 2

    은 디자이너에서 제네릭 컨트롤 (즉, 제네릭을 통해 특수화 된 컨트롤)을 사용할 수 없습니다. [VS 팀의 설계 결정 이었지만 참조를 찾을 수 없음을 읽은 것 같습니다.]

    ObjectListView ListView 컨트롤에 형식화 된 액세스를 제공하기 위해 어댑터 패턴을 사용했습니다.

    public class TypedObjectListView<T> where T : class 
    { 
        /// <summary> 
        /// Create a typed wrapper around the given list. 
        /// </summary> 
        public TypedObjectListView(ObjectListView olv) { 
         this.olv = olv; 
        } 
    
        public void BindTo(IList<T> objects) { 
         // Manipulate the attached ListView here 
        } 
    
        // plus whatever other methods you want 
    } 
    

    하고이 같이 사용할 것이다 : 대신 자신을 다 쓰는,

    TypedObjectListView<Person> tlist = 
        new TypedObjectListView<Person>(this.listView1); 
    tlist.BindTo(myListofPeople); 
    

    또는, 당신은 단지 ObjectListView :)를 사용할 수

    0

    반 방법 집을 얻을 수 있습니다 HierarchicalDataSource 컨트롤이 제네릭 클래스 내에 정의되어 있고 도구 상자에 나타나는 방식은 정의 된 유형의 라이너 하나만 있지만 구체적인 구현을 작성하는 것입니다. 프로젝트를 dll로 컴파일 한 다음 해당 DLL에서 도구 상자에 추가하면 도구 상자 항목이 나타납니다.