我有一个DataTable,里面装满了有关音轨的信息。存储曲目编号的DataTableColumn是一种UInt32类型,因此当我在DataGridView中显示DataTable时,我能够按该列对数据进行排序。对于没有曲目编号的曲目,我在DataTable中有0。
data.Tables["active"].Columns["Track"].DataType = Type.GetType("System.UInt32");在DataGridView中,是否可以将该列中的每个0显示为空字符串(nothing)?但它仍然在DataTable中存储为UInt32 0,以便能够对曲目进行排序吗?
发布于 2013-05-26 03:43:52
当然,您可以使用CellFormatting事件:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].DataPropertyName == "Track")
{
uint value = (uint)e.Value;
if (value == 0)
{
e.Value = string.Empty;
e.FormattingApplied = true;
}
}
}发布于 2013-05-26 03:43:27
只是一个小建议..。添加另一列"System.String“并使其值等于跟踪列(隐藏跟踪列),然后可以在新的可见列中用空字符串替换0
https://stackoverflow.com/questions/16753230
复制相似问题