我有这个未绑定的datagridview在表单加载期间添加列;这是代码;private void loadfields() { dgvbulkentries.ColumnCount = 15; dgvbulkentries.Columns[0].Name = "ID No"; dgvbulkentries.Columns[0].Width = 80; dgvbulkentries.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dgvbulkentries.Columns[1].Name = "Surname"; dgvbulkentries.Columns[1].Width = 150; dgvbulkentries.Columns[2].Name = "First Name"; dgvbulkentries.Columns[2].Width = 150; dgvbulkentries.Columns[3].Name = "Name Extn"; dgvbulkentries.Columns[3].Width = 40; dgvbulkentries.Columns[4].Name = "Middle Name"; dgvbulkentries.Columns[4].Width = 150; dgvbulkentries.Columns[5].Name = "Course"; dgvbulkentries.Columns[5].Width = 110; dgvbulkentries.Columns[6].Name = "Year"; dgvbulkentries.Columns[6].Width = 40; dgvbulkentries.Columns[6].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dgvbulkentries.Columns[7].Name = "Street/Block"; dgvbulkentries.Columns[7].Width = 150; dgvbulkentries.Columns[8].Name = "Subdivision"; dgvbulkentries.Columns[8].Width = 150; dgvbulkentries.Columns[9].Name = "Barangay"; dgvbulkentries.Columns[9].Width = 150; dgvbulkentries.Columns[10].Name = "Municipality/City"; dgvbulkentries.Columns[10].Width = 150; dgvbulkentries.Columns[11].Name = "Province"; dgvbulkentries.Columns[11].Width = 150; 我已经为datagridview中的特定列设置了货币文本框的代码。但是问题是,当我在一个单元格中输入数字时,它根本不会改变。这是我包含的代码;private void dgvbulkentries_CellEndEdit(object sender, DataGridViewCellEventArgs e) { dgvbulkentries.Columns[14].DefaultCellStyle.Format = "n"; }例如,当我在datagridview的特定列中输入数字时,它不会将值格式化为货币格式。我已经按照您的建议做了,但是没有用我错过了什么?
1 回答
LEATH
TA贡献1936条经验 获得超6个赞
如此答案中所述,在知道了问题之后,我认为使用数据网格视图的CellLeave事件将解决您的问题
void dataGridView1_CellLeave(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
{
dgvbulkentries.Columns[14].DefaultCellStyle.Format = "c2";
dgvbulkentries.Columns[14].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("en-GB");
dgvbulkentries.Columns[14].ValueType = typeof(decimal);
}
- 1 回答
- 0 关注
- 193 浏览
添加回答
举报
0/150
提交
取消