110,534
社区成员
发帖
与我相关
我的任务
分享
private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
if (e.Column == gridColumn3)
{
if (e.IsSetData)
{
var aVal = (e.Row as DataRowView)["A"].ToString();
int i;
if (int.TryParse(aVal, out i))
{
if (i % 2 == 0)
{
var color = (Color)e.Value;
(e.Row as DataRowView)["B"] = color.ToArgb().ToString();
}
else
{
(e.Row as DataRowView)["B"] = e.Value.ToString();
}
}
}
if (e.IsGetData)
{
var aVal = (e.Row as DataRowView)["A"].ToString();
int i;
if (int.TryParse(aVal, out i))
{
var bVal = (e.Row as DataRowView)["B"];
if (i % 2 == 0)
{
var color = Color.FromArgb(Convert.ToInt32(bVal));
e.Value = color;
}
else
{
e.Value = bVal.ToString();
}
}
}
}
}
public partial class Form1
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
var dt = new DataTable();
dt.Columns.AddRange(new []{new DataColumn("A", typeof(int)), new DataColumn("B", typeof(string)), });
dt.Rows.Add(1, "white");
dt.Rows.Add(2, "0");
dt.Rows.Add(3, "blue");
dt.Rows.Add(4, "0");
dt.Rows.Add(5, "blue");
dt.Rows.Add(6, "0");
dt.Rows.Add(7, "pink");
dt.Rows.Add(8, "0");
gridControl1.DataSource = dt;
}
private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
if (e.Column == gridColumn3)
{
if (e.IsSetData)
{
var aVal = (e.Row as DataRowView)["A"].ToString();
int i;
if (int.TryParse(aVal, out i))
{
if (i % 2 == 0)
{
var color = (Color)e.Value;
(e.Row as DataRowView)["B"] = color.ToArgb().ToString();
}
else
{
(e.Row as DataRowView)["B"] = e.Value.ToString();
}
}
}
}
if (e.IsGetData)
{
var aVal = (e.Row as DataRowView)["A"].ToString();
int i;
if (int.TryParse(aVal, out i))
{
var bVal = (e.Row as DataRowView)["B"];
if (i % 2 == 0)
{
var color = Color.FromArgb(Convert.ToInt32(bVal));
e.Value = color;
}
else
{
e.Value = bVal.ToString();
}
}
}
}
RepositoryItemColorEdit colorEdit = new RepositoryItemColorEdit();
private void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
{
if (e.Column == gridColumn3)
{
var aVal = gridView1.GetRowCellValue(e.RowHandle, "A").ToString();
int i;
if (int.TryParse(aVal, out i))
{
if (i%2 == 0)
{
e.RepositoryItem = colorEdit;
}
}
}
}
}