因此,我已经看到了其他有关此问题的问题,但是我一生都无法将我的网格格式作为货币浮动。这是我的简单项目,它有一个名为 gridcontrol1 的网格控件,有 4 列,我希望最后一个是货币,其他 3 个是字符串。
public partial class Form1 : Form
{
private DevExpress.XtraGrid.GridControl gridControl1;
private DevExpress.XtraGrid.Views.Grid.GridView gridView1;
private DevExpress.XtraGrid.Columns.GridColumn gridColumn1;
private DevExpress.XtraGrid.Columns.GridColumn gridColumn2;
private DevExpress.XtraGrid.Columns.GridColumn gridColumn3;
private DevExpress.XtraGrid.Columns.GridColumn gridColumn4;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ArrayList test = new ArrayList();
test.Add(new MyObject() { myCurrency = 1.5F, prop1 = "hi", prop2 = "hi2", prop3 = "hi3" });
gridColumn4.DisplayFormat.FormatString = "c";
gridColumn4.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
gridControl1.DataSource = test;
gridControl1.MainView.PopulateColumns();
gridControl1.RefreshDataSource();
}
}
public class MyObject
{
public string prop1 { get; set; }
public string prop2 { get; set; }
public string prop3 { get; set; }
public float myCurrency { get; set; }
}
我已经尝试了自定义和数字的“c”、“c2”、“N”、“N2”和 FormatType 格式字符串以及它们的任何组合,结果与在框中列出的“1.5”相同。我做错了什么简单的事情吗?这不可能那么难!