c# DataGridView,列乘数格式

本文关键字:格式 DataGridView | 更新日期: 2023-09-27 18:09:44

我目前正在尝试为最初放入数据网格视图的任何值设置乘数。

如果我在

下面做类似的操作
for(int i = 0; i < 20; i++)
{
    dataGridView1.Rows.Add(i * 2000, i*3000, i*4000);      
}

第一行是2000。我想做的是使它显示为2,而不是实际修改被放置到datagridview中的值。

我试着玩这个,但我不确定什么放入括号得到除以1000

dataGridView1.Columns[0].DefaultCellStyle.Format = "000."; 
// just playing around with how this behaves 

谢谢

c# DataGridView,列乘数格式

尝试DataGridView CellFormatting,如下所述:http://msdn.microsoft.com/en-us/library/z1cc356h.aspx?ppud=4

private void dataGridView1_CellFormatting(object sender,
    DataGridViewCellFormattingEventArgs e)
    {
        if (e.ColumnIndex == 0)
        {
            e.Value = Convert.ToInt32(e.Value.ToString()) * 2000 // apply     formating here
            e.FormattingApplied = true;
        }
        //repeat for additional columns
     }

第一行是2000

不,因为ii = 0开始,所以是0

我想做的是使它显示为2,而不是实际上修改放入datagridview中的值。

我相信你可以除以1000得到那个值

Convert.ToInt32(dataGridView1.Rows[0].Cells[0].Value) / 1000; // produce 2