【问题标题】:How to change gridview's column format type and format string on runtime?如何在运行时更改gridview的列格式类型和格式字符串?
【发布时间】:2021-10-01 18:31:12
【问题描述】:

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

我可以在下面的代码块中更改格式类型和格式字符串,但是当我尝试获取已更改列的格式字符串时。 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", "****");
 }

【问题讨论】:

    标签: c# winforms devexpress


    【解决方案1】:

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

    类似这样的:

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

    【讨论】:

      猜你喜欢
      • 2016-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      • 2013-08-26
      • 1970-01-01
      • 2012-05-27
      相关资源
      最近更新 更多