111,086
社区成员




public class DataGridViewTextBoxCellEx : DataGridViewTextBoxCell
{
public DataGridViewTextBoxCellEx()
{
}
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
//base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
if (value != null && value.ToString() != "")
{
Image img=Image.FromFile(value.ToString());
if(img!=null)
{
graphics.DrawImage(img, cellBounds);
}
}
}
}
DataGridViewColumn column = dataGridView1.Columns[1];//换成你实际的列
DataGridViewCell cell =new DataGridViewTextBoxCellEx();
column.CellTemplate = cell;
//绑定到DataGridView
private void BindDategridview()
{
dataGridView1.Rows.Clear();
dataGridView1.DataSource = null;
//dataGridView1.Rows.Add(5);
//DataSet ds = Bll.GetList("Cus_Id='" + cmbsgbw.Text + "'");
DataSet ds = Bll.GetList("Cus_Id='" + Detail.cuid + "'");
if (ds.Tables[0].Rows.Count > 0)
{
dataGridView1.Rows.Add(ds.Tables[0].Rows.Count);
string[] str = new string[23];
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
for (int k = 0; k < str.Length; k++)
{
str[k] = ds.Tables[0].Rows[i].ItemArray[k].ToString();
//if (str[k] == "0")
// str[k] = false.ToString();
//else if (str[k] == "1")
// str[k] = true.ToString();
string s = Class_Path.position + "\\ysimage\\" + ds.Tables[0].Rows[i]["XZ_bianhao"].ToString() + ".jpg";
str[5] = s;
}
//for (int p = 0; p < dataGridView1.Rows.Count; p++)
//{
for (int q = 0; q < dataGridView1.Columns.Count; q++)
{
if (q == 5)
dataGridView1.Rows[i].Cells[5].Value = Image.FromFile(str[q]);
else
dataGridView1.Rows[i].Cells[q].Value = str[q];
}
//}
}
}
DataGridViewImageColumn img_column = new DataGridViewImageColumn();
dataGridView1.Columns.Add(img_column);
img_column.HeaderText = "image";
img_column.Name = "image";
img_column.Image = System.Drawing.Image.FromFile(pictureBox1.ImageLocation.ToString());