2012-05-21 18 views
8

में प्रतिशत (%) दिखाने के लिए कॉलम को प्रारूपित करने के लिए कैसे मेरे पास एक संग्रहित प्रक्रिया से मूल्यों के साथ एक xtragrid है।
मुझे फ्लोट (0.23) में मान मिल रहा है और मैं प्रतिशत (23%) में प्रदर्शित करना चाहता हूं।
सी # में ऐसा करने का सबसे अच्छा तरीका क्या होगा?xtragrid

से पहले before के बाद after

उत्तर

10

उपयोग CustomDrawCell घटना तुम सिर्फ केवल पढ़ने के लिए सेल प्रदर्शित करने के लिए चाहते हैं। या आप CustomColumnDisplayText Event का भी उपयोग कर सकते हैं।

इस प्रयास करें:

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() + "%"; 
       } 
      } 

एक और तरीका संपादक EditFormat और DisplayFormat संपत्ति का उपयोग करें। रेफरी:: और सेट करने के बाद इन गुणों gridview स्तंभ में जोड़ने 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; 

     } 

सबसे आसान तरीका GridColumn.DisplayFormat संपत्ति का उपयोग करें।

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

आशा इस मदद ..

+1

वही है जो मैं खोज रहा था। सभी संदर्भों के लिए +1। – Stavros

+0

अच्छा, और यह मुझे बाइट/tinyint के रूप में percents स्टोर करने की अनुमति भी - धन्यवाद! अन्यथा ग्रिडकंट्रोल डेटा की व्याख्या नहीं कर रहा था जैसा कि मैं चाहता था -> 10 प्रतिशत 1000% में बदल गया :) – Prokurors

+0

पृथ्वी पर यह स्वीकार्य उत्तर क्यों है? – Aron

8

निम्नलिखित दृष्टिकोण का उपयोग करें:

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

संबंधित लिंक:

+0

राजधानी 'P' आप 1' के प्रारूप में छोटे' p' का उपयोग करना चाहिए पैमाने '0 का उपयोग करना चाहते हैं,' 50 50% के रूप में 'यह व्यवहार करेगा स्ट्रिंग .. –

+0

@ निर्जनंजन: धन्यवाद। यह मेरी गलती है। मैंने अपना जवाब अपडेट कर लिया है। – DmitryG