2017-06-23 15 views

回答

0

看看這個鏈接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; 
     } 
    } 
}