Completed
Last Updated: 09 Jun 2015 06:06 by ADMIN
ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 16 Jan 2015 07:19
Category: GridView
Type: Bug Report
0
FIX. RadGridView - GridViewCommandColumn.FormatString property is reset when save/load layout operation is performed
To reproduce:

public Form1()
{
    InitializeComponent();
   
    GridViewDecimalColumn decimalColumn = new GridViewDecimalColumn("DecimalColumn");
    decimalColumn.FormatString = "{0:N0}";
    decimalColumn.FieldName = "Price";
    radGridView1.MasterTemplate.Columns.Add(decimalColumn);

    GridViewCommandColumn commandColumn = new GridViewCommandColumn("CommandColumn");
    commandColumn.FormatString = "{0:N0}";
    commandColumn.FieldName = "Price";
    radGridView1.MasterTemplate.Columns.Add(commandColumn);
    radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    
    this.radGridView1.SaveLayout(@"..\..\..\layout.xml");
    this.radGridView1.LoadLayout(@"..\..\..\layout.xml");
    
    FillData();
}

private void FillData()
{
    List<Item> items = new List<Item>();
    for (int i = 0; i < 5; i++)
    {
        items.Add(new Item(i * 2.35m));
    }
    radGridView1.DataSource = items;
}

public class Item
{
    public decimal Price { get; set; }

    public Item(decimal price)
    {
        this.Price = price;
    }
}

Workaround: use the CellFormatting event and format the GridCommandCellElement.CommandButton.Text property:
private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.Column is GridViewCommandColumn && e.CellElement.Value != null)
    {
        GridCommandCellElement commandCell = e.CellElement as GridCommandCellElement;
        commandCell.CommandButton.Text = string.Format("{0:N0}", e.CellElement.Value);
    }
}
0 comments