을 감사 할 것입니다 무엇을 궁금해. 예 :
var images = new Dictionary<char, Image>()
{
{'#', Properties.Resources.Image1},
{'.', Properties.Resources.Image2},
{'$', Properties.Resources.Image3},
{'@', Properties.Resources.Image4},
};
var data = new List<string>() { "#.#", "#$#", "#@#", "###" };
var list = data.Select(x => new
{
A = images[x[0]],
B = images[x[1]],
C = images[x[2]]
}).ToList();
this.dataGridView1.DataSource = list;
위 코드에서 문자와 이미지 간의 매핑을위한 사전을 만들었습니다. 그런 다음 문자 대신 해당 이미지가 포함 된 목록에 입력 데이터를 형성합니다. 결과 목록을 DataSource
(DataGridView
)으로 설정하면 문자 대신 해당 이미지가 표시됩니다.
익명 객체를 사용하지 않으려는 어떤 이유로, 당신은 단순히 열 동적 DataTable
가진 숫자 만들 수 있습니다 경우 : a`DataGridView` 가장 간단한 옵션 사용
var images = new Dictionary<char, Image>()
{
{'#', Properties.Resources.Image1},
{'.', Properties.Resources.Image2},
{'$', Properties.Resources.Image3},
{'@', Properties.Resources.Image4},
};
char[][] data = new char[][]{
new char[] {'#','.','#'},
new char[] {'#','$','#'},
new char[] {'#','@','#'},
new char[] {'#','#','#'},
};
var dt = new DataTable();
for (int i = 0; i < data.Max(x => x.Count()); i++)
dt.Columns.Add(string.Format("C{0}", i), typeof(Image));
data.ToList().ForEach(a => dt.Rows.Add(a.Select(x=>images[x]).ToArray()));
this.dataGridView1.DataSource = dt;
을 . –
[2 차원 배열을 기반으로 WPF 격자를 채우는 방법] 가능한 복제본 (http://stackoverflow.com/questions/276808/how-to-populate-a-wpf-grid-based-on-a- 2 차원 배열) – rmbq