2012-05-21 55 views

Trả lời

10

Sử dụng CustomDrawCell sự kiện nếu bạn chỉ muốn hiển thị các tế bào chỉ đọc. hoặc Bạn cũng có thể sử dụng số CustomColumnDisplayText Event.

Hãy thử điều này:

private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) 
      { 
       if (e.Column.FieldName == "Marks") 
       { 
        e.DisplayText = (((int)(Convert.ToDecimal(e.CellValue) * 100))).ToString() + "%"; 
       } 
      } 

Một cách khác sử dụng tài sản biên tập EditFormat và DisplayFormat. và sau khi cài đặt các thuộc tính bổ sung nó vào cột GridView: Ref: How to format values shown in the XtraGrid

RepositoryItem textEdit; 
     private void AddGridRepositoryItem() 
     { 
      textEdit = new RepositoryItemTextEdit(); 
      textEdit.AllowHtmlDraw = DevExpress.Utils.DefaultBoolean.True; 
      textEdit.ReadOnly = true; 
      gridControl1.RepositoryItems.Add(textEdit); 

      textEdit.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric; 
      textEdit.DisplayFormat.FormatString = "p"; 
      gridView1.Columns[0].ColumnEdit = textEdit; 

     } 

Cách đơn giản nhất là sử dụng GridColumn.DisplayFormat tài sản.

colPayment.DisplayFormat.FormatType = FormatType.Numeric; 
colPayment.DisplayFormat.FormatString = "p0"; 

Hope trợ giúp này ..

+1

Đó chính xác là những gì tôi đang tìm kiếm. 1 cho tất cả các tham chiếu. – Stavros

+0

Đẹp, và điều này cũng cho phép tôi lưu trữ phần trăm như byte/tinyint - cảm ơn! Nếu không GridControl đã không giải thích dữ liệu như tôi muốn -> 10 phần trăm biến thành 1000% :) – Prokurors

+0

Tại sao trên trái đất này là câu trả lời được chấp nhận? – Aron

8

Vui lòng sử dụng phương pháp sau:

colReabilitation.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric; 
colReabilitation.DisplayFormat.FormatString = "p0"; 

liên kết liên quan:

+0

vốn 'P' sẽ đối xử với nó là '50 đến 50%', nếu bạn muốn sử dụng quy mô '0 đến 1' phải sử dụng nhỏ' p' ở định dạng chuỗi .. –

+0

@NiranjanKala: Cảm ơn. Đó là sai lầm của tôi. Tôi đã cập nhật câu trả lời của mình. – DmitryG

Các vấn đề liên quan