How to custom format data in datagridview during databinding

前端 未结 7 788
忘掉有多难
忘掉有多难 2020-12-16 14:21

I\'m looking for a way to format DataGridViewTextBoxColumn so that the value to be databinded is formatted during databinding. For example I have a CompanyName property and

7条回答
  •  青春惊慌失措
    2020-12-16 15:09

    I don't know about the IFormatProvider, but can the DataGridViews CellFormatting-event help you?

    private void dataGridView1_CellFormatting(object sender,
        DataGridViewCellFormattingEventArgs e)
    {
        if (e.ColumnIndex == 0)
        {
            e.Value = e.Value.ToString().Substring(0, 5); // apply formating here
            e.FormattingApplied = true;
        }
    }
    

    http://msdn.microsoft.com/en-us/library/z1cc356h.aspx?ppud=4

提交回复
热议问题