如何在运行时更改网格视图的列格式类型和格式字符串?



如果用户没有授权,我想用一个特殊字符而不是数字来显示价格。

我可以在下面的代码块中更改格式类型和格式字符串,但是当我试图获得更改列的格式字符串时。colPRICE.DisplayFormat.GetFormatString()等于{0},{0}只接受数值。如何压缩{0}?

colPRICE.DisplayFormat.FormatType = FormatType.Custom;
colPRICE.DisplayFormat.FormatString = "";
var formatStringPrice = colPRICE.DisplayFormat.GetFormatString();
for (int i = 0; i < gridView1.RowCount; i++)
{
gridView1.SetRowCellValue(i, "PRICE", "****");
}

我将保持格式不变,并处理GridView的CustomDrawCell事件。

像这样:

private void gridView1_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e) 
{
if (!DoesUserHaveAuth())
{
e.DisplayText = "******";
}
}

最新更新