I have a table payments that has a null-able integer column named payMonth. I have the following class and list:
public class months
{
public int payMonth { get; set; }
public string monthName { get; set; }
}
lstMonths = new List<months> {
,new months() { payMonth = 1, monthName = "jan" }
,new months() { payMonth = 2, monthName = "feb" }
,new months() { payMonth = 3, monthName = "mar" }
,new months() { payMonth = 4, monthName = "apr" }
,new months() { payMonth = 5, monthName = "may" }
,new months() { payMonth = 6, monthName = "jun" }
,new months() { payMonth = 7, monthName = "jul" }
,new months() { payMonth = 8, monthName = "aug" }
,new months() { payMonth = 9, monthName = "sep" }
,new months() { payMonth = 10, monthName = "oct" }
,new months() { payMonth = 11, monthName = "nov" }
,new months() { payMonth = 12, monthName = "dec" }};
cmbMonth = new DataGridViewComboBoxColumn();
cmbMonth.DataSource = lstMonths;
cmbMonth.ValueMember = "payMonth";
cmbMonth.DisplayMember = "monthName";
cmbMonth.DataPropertyName = "payMonth";
cmbMonth.Name = "cmbPayMonth";
cmbMonth.HeaderText = "Month";
cmbMonth.FlatStyle = FlatStyle.Flat;
cmbMonth.Width = 80;
dgvPayments.Columns.Insert(5, cmbMonth);
The problem comes here. When data is displayed in the dgv, the DataGridViewComboBoxColumn cmbMonth shows the number values (1,2,3, ...) not the month name ('Jan','Feb','Mar', ...). And when i click the dgv it display the error: formatting, display and some times formatting, preferredSize. When I remove the DataPropertyName property, this error goes but data are not displayed. Though, the payMonth values in the table are only in the list range or is null.
This is payments table:
Whats wrong?
DataGridVIew
?payMonth
column in payment table? Is itInt32
as in months list?