应用自定义单元格格式后,从datagridview获取单元格值

时间:2015-05-28 09:15:55

标签: c# datagridview

我有一个DataGridView

我的代码:

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (dataGridView1.Columns[e.ColumnIndex].Name == BaoDuong.DVThucHien)
    {
        e.Value = "BTWASECO";
        e.FormattingApplied = true;
    }
}

////单击单击

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{  
    MessageBox.Show(dataGridView1.CurrentRow.Cells[e.ColumnIndex].Value.ToString());
}

我想获得价值" BTWASECO",但结果是:http://upanhtocdo.com/image.php?di=IM76

1 个答案:

答案 0 :(得分:1)

格式化

后,

dataGridView1.CurrentRow.Cells[e.ColumnIndex].Value尚未更改

尝试使用FormattedValue

MessageBox.Show(dataGridView1.CurrentRow.Cells[e.ColumnIndex].FormattedValue.ToString());