2012-02-11 32 views
0

在我的表單加載事件中,我設置了默認的cellstyle格式。他們沒有掌握任何人知道爲什麼?格式都不是在代碼預期後,我將DataTable綁定到網格是越來越即使代碼步驟,通過做到了datagridview格式不適用

Private Sub frmADRORD_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

    'wire the delegate function for incoming updates 
    AddHandler m_helper.DataUpdate, AddressOf UpdateGridInvoker 
    'bind the visual grid with the binding source 
    Me.datagridADRORD.DataSource = dsGridView 

    'get data from helper class 
    m_dt = m_helper.GetTable() 

    'bind the binding source with datatable 
    Me.datagridADRORD.DataSource = m_dt 

    **'after data loaded, auto resize columns and format 
    Me.datagridADRORD.AutoResizeColumn(DataGridViewAutoSizeColumnMode.AllCellsExceptHeader) 
    With Me.datagridADRORD.ColumnHeadersDefaultCellStyle 
     .BackColor = Color.Gold 
     .Alignment = DataGridViewContentAlignment.MiddleCenter 
     .WrapMode = DataGridViewTriState.True 
     .Font = New Font(Control.DefaultFont, FontStyle.Bold) 
    End With 
    Me.datagridADRORD.Columns("ADR Price").DefaultCellStyle.Format = "##.##" 
    For Each row As DataGridViewRow In Me.datagridADRORD.Rows 
     row.Cells("ORD Price").DataGridView.DefaultCellStyle.FormatProvider = Globalization.CultureInfo.GetCultureInfo(m_helper.CurrCultureInfoStr(row.Cells("Currency").Value)) 
    Next 
    Me.datagridADRORD.Columns("Currency Price").DefaultCellStyle.Format = "##.####" 
    Me.datagridADRORD.Columns("Difference").DefaultCellStyle.Format = "##.##"** 
End Sub 

回答

2

你要設置列的ValueType,和「##。 ##「似乎不起作用(反正C#)。

這個工作在C#:

 this.dataGridView1.Columns["Column3"].ValueType = typeof(Double); 
     this.dataGridView1.Columns["Column3"].DefaultCellStyle.Format = "N2"; 

而且數據被綁定有實際上是某些數字類型(我相信它是,但不能從您的代碼段確定)的。

您必須將typeof()翻譯爲等效的VB.NET,並且我不知道「##。##」和「N2」之間的區別是否是控件(在這種情況下您需要改變它)或語言的東西(在這種情況下你不會)。