C# 如何控制value.ToString在DataGridViewTextBoxColumn中的工作方式?
具有类似以下内容的C# 如何控制value.ToString在DataGridViewTextBoxColumn中的工作方式?,c#,.net,winforms,C#,.net,Winforms,具有类似以下内容的DataGridViewTextBoxColumn: var decayTimeColumn = new DataGridViewTextBoxColumn { DataPropertyName = "DecayTimeUi", HeaderText = @"half-life" }; 它在列表上运行,其中T具有.DecayTimeUigeter returning float如何控制它的显示方式(设置它的值.ToString(“E”,CultureInfo.Inva
DataGridViewTextBoxColumn
:
var decayTimeColumn = new DataGridViewTextBoxColumn
{
DataPropertyName = "DecayTimeUi",
HeaderText = @"half-life"
};
它在列表
上运行,其中T具有.DecayTimeUi
geter returning float如何控制它的显示方式(设置它的值.ToString(“E”,CultureInfo.InvariantCulture)
而不是默认的ToString
)?通过以下命令设置单元格的值:
但是,它只支持字符串,因此不能以这种方式指定强类型区域性;您需要找到适用于您的情况的速记格式字符串。甚至无法设置DefaultCellStyle-编译错误(在您提供的代码上):
错误当前上下文中不存在名称“DefaultCellStyle”
那么您可以做什么:DefaultCellStyle=new DataGridViewCellStyle{Format=“E”}
,还是不行?我可以作为下一行:`decayTimeColumn.DefaultCellStyle.Format=“E”`,编译、工作。
var decayTimeColumn = new DataGridViewTextBoxColumn {
DataPropertyName = "DecayTimeUi",
HeaderText = @"half-life",
DefaultCellStyle.Format = "E"
};