如何在运行时更改 gridview 的列格式类型和格式字符串?
How to change gridview's column format type and format string on runtime?
如果用户没有授权,我想用特殊字符而不是数字来显示价格。
我可以在下面的代码块中更改格式类型和格式字符串,但是当我尝试获取已更改列的格式字符串时。 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 = "******";
}
}
如果用户没有授权,我想用特殊字符而不是数字来显示价格。
我可以在下面的代码块中更改格式类型和格式字符串,但是当我尝试获取已更改列的格式字符串时。 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 = "******";
}
}