【问题标题】:How to change cell format on load time in DevExpress Winform如何在 DevExpress Winform 中更改加载时间的单元格格式
【发布时间】:2017-06-23 08:56:15
【问题描述】:

我想在 GridView 中加载单元格时更改单元格格式、单元格值、对齐方式。

【问题讨论】:

    标签: winforms devexpress


    【解决方案1】:

    看看这个链接https://documentation.devexpress.com/windowsforms/3048/Controls-and-Libraries/Data-Grid/Examples/Formatting/How-to-Format-Display-Text-in-Grid-s-Cells-Depending-on-Values-in-Other-Cells

    using DevExpress.XtraGrid.Views.Base;
    using System.Globalization;
    
    // The cultures used to format the values for the two different currencies. 
    CultureInfo ciUSA = new CultureInfo("en-US");
    CultureInfo ciEUR = new CultureInfo("fr-FR", false);
    
    private void gridView1_CustomColumnDisplayText(object sender, CustomColumnDisplayTextEventArgs e) 
    {
    
        ColumnView view = sender as ColumnView;
    
        if (e.Column.FieldName == "Price" && e.ListSourceRowIndex != DevExpress.XtraGrid.GridControl.InvalidRowHandle)
        {
           int currencyType =   (int)view.GetListSourceRowCellValue(e.ListSourceRowIndex, "CurrencyType");
           decimal price = Convert.ToDecimal(e.Value);
           switch (currencyType)
           {
             case 0: e.DisplayText = string.Format(ciUSA, "{0:c}", price); break;
             case 1: e.DisplayText = string.Format(ciEUR, "{0:c}", price); break;
           }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-19
      • 2021-02-22
      • 1970-01-01
      • 1970-01-01
      • 2021-04-06
      • 2012-12-29
      相关资源
      最近更新 更多