ReadOnlyCollection을 DataGridView에 바인딩하는 방법
SELECT
"Id", "FullName", "Foreground", "Blink", "Background", "TypeDesc", "MemoryUsage"
FROM
"CCustomColour"
ORDER BY
"FullName" ASC
및 결과는 QueryResult으로 나에게 돌아왔다 : 나는 데이터 그리드 다른 몇 가지에 행의 ReadOnlyCollection을 결합하는 시도
using System.Collections.ObjectModel;
namespace ClearScada.Client.Advanced
{
//
public class QueryResult
{
//
// Summary:
// Gets the results of the query.
public ReadOnlyCollection<QueryRow> Rows { get; }
//
// Summary:
// Gets the number of rows affected for a DML query.
public int RowsAffected { get; }
//
// Summary:
// Gets the status of the query.
public QueryStatus Status { get; }
}
}
방법.
dataGridViewResults.DataSource = this.MyQueryResult.Rows;
및
BindingSource bs = new BindingSource();
bs.DataSource = this.MyQueryResult.Rows;
dataGridViewResults.DataSource = bs;
격자 날만을 행 인덱스하지만 데이터를 나타내는 단일 열을 도시한다 : 여기에 참고로
는 QueryRow 클래스의 정의이며 :
using System.Collections.ObjectModel;
namespace ClearScada.Client.Advanced
{
//
public class QueryRow
{
//
public ReadOnlyCollection<object> Data { get; }
//
public int Index { get; }
}
}
이 무엇을 달성하려고하는 것은 : 여기 보여 비주얼 스튜디오에서 '현지인'창에서의 전망을 캡처 할 수 있도록
0 내 QueryResult 인스턴스의 로컬 복사본을 생성
당신은 내가있는 DataGridView에 그 값을 바인딩 할 수있는 방법을 나에게 보여줌으로써 좀 도와 주시겠습니까 : 다음과 같이 표시하는보기?
'dataGridViewResults.DataSource = this.MyQueryResult.Rows.ToList()'를 시도 해 보셨습니까? – Ingenioushax
아이디어를 주셔서 감사 드리며, 저는 이것을 구현하려고 시도했지만 'this.MyQueryResult.Rows'에는 ToList 메소드가 없습니다. 그것은 단지 두 개의 메소드, CopyTo와 ToString만을 노출합니다. CopyTo 메서드를 사용하면 행의 ReadOnlyCollection을 QueryRow 개체의 배열에 복사 할 수 있습니다. 나는 이것을 시도한 다음 결과 배열에서 ToList 메서드를 찾았지만 다시 ToList 메서드가 없습니다. – Experimentalist
직선 변환 대신 목록 생성자는 어떻게됩니까? 'List mqr = 새로운 목록 (this.MyQueryResults);'? –
Ingenioushax