c# - 如何在运行时更改gridview的列格式类型和格式字符串?
问题描述
如果用户没有授权,我想用特殊字符而不是数字显示价格。
我可以在下面的代码块中更改格式类型和格式字符串,但是当我尝试获取已更改列的格式字符串时。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 = "******";
}
}
推荐阅读
- javascript - “electron.exe”从何而来?
- c# - C# MongoDB 过滤器返回整个对象
- javascript - 使用 Promise.all() 并将方法放入 fetch 时 JSON 输入意外结束
- session - 通过 http 的内部应用程序之间的私有 cookie
- vue.js - 在 VUEX 中进行 CRUD 操作后我该怎么办
- azure-web-app-service - 在 Azure 中使用 MigraDoc (PdfSharp) 渲染 µ 和 ³ 时出现问题
- simulation - AnyLogic:使用每个代理一行填充时间颜色图
- python - 我收到此错误“ValueError: Shapes (None, 256, 256, 2) and (None, 256, 256, 1)在尝试训练模型进行分割时不兼容
- c++ - 意外的参考行为
- data-science - 如何在 Google Data Studio 中将日期转换为有效格式?