【发布时间】:2017-04-06 15:01:24
【问题描述】:
我有一个通过 Linq 绑定到数据源的 XtraGridview,当我选中某个复选框时,我需要将图像设置到单元格中以及它们已经拥有的值。 现在,当我选中复选框时,我将图像设置在单元格中就好了,但消除了单元格值(数据)。 在 CustomDrawCell 事件中我会这样做
private void gridView_GD_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
{
GridView view = sender as GridView;
string evento1 = Convert.ToString(view.GetRowCellValue(e.RowHandle, "Eve1"));
if (CVariables.Ficon_estado == 1)
{
if (evento1 == "06" || evento1 == "15")
{
if (e.Column.FieldName == "G1")
{
e.Handled = true;
Point pos = CalcPosition(e, imageCollection_16.Images[1]);
e.Graphics.DrawImage(imageCollection_16.Images[1], pos);
view.Columns["G1"].AppearanceCell.BackColor = Color.Transparent;
view.Columns["G1"].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
}
}
}
else
{
view.Columns["G1"].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
}
}
private Point CalcPosition(RowCellCustomDrawEventArgs e, Image img)
{
Point p = new Point();
p.X = e.Bounds.Location.X + (e.Bounds.Width - (img.Width * 3)) / 2;
p.Y = e.Bounds.Location.Y + (e.Bounds.Height - img.Height) / 2;
return p;
}
【问题讨论】:
标签: c# winforms gridview devexpress