我正在用从MySQL表中选择的数据填充dataGridView,代码如下
MySqlConnection sqlConnection = new MySqlConnection(sqlParams);
try
{
MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = new MySqlCommand(sqlQuery, sqlConnection);
DataSet ds = new DataSet();
adapter.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.Sort(dataGridView1.Columns["ColumnName"], ListSortDirection.Ascending);
}
catch {
}
其中一列包含sum数据(例如10.34USD),但问题是,在我的国家格式中,它必须是"10,34“(coma而不是dot),所以我想在填充dataGridView时更改此符号。有可能吗?或者还有其他方法吗?因为现在我以“点”格式存储和,因为我可以使用像SUM这样的MySQL命令。
简而言之:在MySQL中,我有10.34,但用户必须看到10,34 :)
发布于 2013-03-11 21:49:10
是的,这是可能的。可以在datagridview中设置格式。
dataGridView1.Columns["ColumnName"].DefaultCellStyle.Format = "C";
"C“表示货币格式。"N“表示常规数字格式。此外,对于特定于您的国家/地区的格式,您可以使用CultureInfo类,在该类中可以为当前线程设置特定的格式提供程序。
https://stackoverflow.com/questions/15349128
复制