datagridview格式不适用



在表单加载事件中,我正在设置defaultcellstyle格式。他们没有抓住任何人知道为什么吗?在我将数据表绑定到网格后,代码中预期的任何格式化都没有完成,即使代码通过

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

您必须设置列的ValueType,而"###.##"似乎不起作用(无论如何在C#中)。

这在C#中有效:

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

此外,绑定的数据实际上必须是某种数字类型(我认为是,但不能从代码片段中确定)。

你必须将typeof()翻译成等效的VB.NET,我不知道"###.##"one_answers"N2"之间的区别是控制问题(在这种情况下你需要更改它)还是语言问题(在那种情况下你不会)。

最新更新