2013-08-08 5 views
0

개체 목록이 있습니다. 내 클래스는 다음과 같습니다C# 일반 목록 필터

class Line 
    { 
    public string A { get; set; } 
    public object B { get; set; } 
    public string C { get; set; } 
    } 

class More_B 
{ 
    public Information Information { get { return _Information; }} 
    public Description Description { get { return _Description ; }} 

    private Information _Information = new Information(); 
    private Description _Description = new Description(); 
} 

class Information 
{ 
    public string Name { get; set;} 
    public string Type { get; set;} 
    public string Further_Info { get; set;} 
} 

를 내 메인 클래스에서이 같은 Line 클래스 내부의 모든 데이터를 얻을 수 끝에.

More_B info = new More_B(); 

Line main = new Line(); 
main.A = "Information about device"; 
main.B = info; 
main.C = "Some more information could be display here"; 
list3.Add(main); 

그래서 말에 나는 어떤 안에 내가 3 개 필드 ABC이 목록을 가져옵니다. AC에 내 문자열 값이 있고 B에 디버그 모드를 확인할 때 정보 객체가 있고 그 안에는 NameTypeFurther_Info과 같은 모든 필드가 있습니다.

나중에이 값을 "Name" "Type"및 "Further_Info"값을 기준으로 필터링하려면이 방법을 시도했지만 작동하지 않습니다. (RowFilter를 사용할 수 있도록 DataView에 내 목록을 바인딩했습니다.)

view2.RowFilter = "Line like '%" + textBox2.Text + "%'"; 

어떻게하면됩니까?

저는 C#에 익숙하지 않습니다. 제발 잘못했으면 용서해주세요. 이해하기 어려운 것이 있으면 알려주세요. 내가 한 일을 설명하는 코드를 더 게시하려고합니다.

편집 : 나는이 문장 view2.RowFilter = "Line like '%" + textBox2.Text + "%'";를 사용할 때 나는 오류 Cannot perform 'Like' operation on read_display.More_B and System.String.

EDIT2를 얻을 : 내 클래스에 대한 데이터 테이블 작성을위한 2 개 방법이 다음 내가 이런 식으로 작업을 수행합니다 DataTable ListAsDataTable2 = BuildDataTable2<Line>(list3); DataView ListAsDataView2 = ListAsDataTable2.DefaultView; this.dataGridView4.DataSource = view2 = ListAsDataView2;

+0

'view2' 란 무엇입니까? – xanatos

+0

view2는 내 DataView의 개체입니다. RowFilter를 사용하려면이 방법을 사용했습니다. 이 데이터를 DataView에 바인딩하지 않으면 작동하지 않습니다. – user2592968

+0

Binding에 사용하는 우편 번호 –

답변

3

시도를 이런 식으로 :

public class Line 
{ 
    public string A {get;set;} 
    public More_B B {get;set;} 
    public string C {get;set;}   

} 

public class Information 
{ 
    public string Name { get; set;} 
    public string Type { get; set;} 
    public string Further_Info { get; set;} 
} 

public class More_B:Information 
{ 
    public string CusotmField {get;set;} 
} 

var B_Object = new More_B (Name = "The B", Type = "Some type", Further_Info = "More Info"); 
IList<More_B> B_List=new List<More_B>(); 
var searchObj = B_List.Where(x => x.Name=="The B").FirstOrDefault(); 
+0

이것이 도움이되는지 확인하겠습니다. 고맙습니다. – user2592968

+0

위대한, 그것은 나를 많이 도왔습니다. 고맙습니다!! – user2592968

+0

당신은 환영합니다 :) –

0

나는 RowFilter에 오류가 있다고 생각합니다. Line은 열이 아니므로 Filter에서 사용하면 안됩니다. 아마도 다음과 같은 것을 찾고있을 것입니다 :

view2.RowFilter = "Name like '%" + textBox2.Text + "%' OR Type like '%" + textBox2.Text + "%' OR Further_Info like '%" + textBox2.Text + "%' " 
+0

그것은 작동하지 않습니다, 미안 해요. – user2592968