을, 물론 그려진 이미지는 text
(설명 파일에 대응 유형 : 예 : .pdf
, .txt
, ...). 모든 이미지를 직접 준비해야합니다. 알 수없는 파일 유형에 해당 이미지가 없으면 Unknown file type image
을 사용할 수 있습니다. 예를 동적으로이 작업을 수행 할 수
//Dictionary to store the pairs of `text` and the corresponding image
Dictionary<string, Image> dict = new Dictionary<string, Image>(StringComparer.CurrentCultureIgnoreCase);
//load data for your dict
dict["Unknown"] = yourUnknownImage;//This should always be added
dict[".pdf"] = yourPdfImage;
dict[".txt"] = yourTxtImage;
//.....
//CellPainting event handler for your dataGridView1
//Suppose the column at index 1 is the type column.
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e){
if(e.ColumnIndex == 1 && e.RowIndex > -1){
var image = dict["Unknown"];
if(e.Value != null) {
Image img;
if(dict.TryGetValue(e.Value.ToString(), out img)) image = img;
}
//Draw the image
e.Graphics.DrawImage(image, new Rectangle(2,2, e.Bounds.Height-4, e.Bounds.Height-4));
}
}
당신이 아직 아이디어를 시도했지만 이유를 대신 템플릿 필드를 사용 : 셀에 이미지를 그리려면 이벤트
CellPainting
를 처리 할 수 있고, 여기에 코드입니다 당신은 시도 할 수 있습니다? 'BoundField'는'imagebutton'을 사용합니다. 그러나 이것은'PdF'에 대한 상수 이미지를 주거나'RowBound' 이벤트에 이미지를 동적으로 추가하거나 이미'Pdf'에 대한 이미지가 있습니까? –혼란스러운 질문입니까? 열 유형을 변경 하시겠습니까? 열 이름 또는 열 필드의 내용? – Remy