I'm currently working on a C# desktop app for a school project, I'm a student and henceforth, a beginner. I have an issue which is giving me a lot a trouble.
I load a list of object (From DB) into a DatagridView via .datasource . So far no specific problem. Each object of the list has a color assigned to it.
The Column Type is set to DataGridViewComboBoxColumn in visual studio properties. (See settings in following code)
Once on the DGV, when I click on the color cell of any row of the color column, I have the full list of static data displayed. I can select any color of the list. However if I hit enter or leave the row, the initial color comes back...
Exemple: The color from DB is "Red", I select "Yellow" from the combo, hit enter, the cell reverts back to "Red"...
What am I missing?
Thanks for any help!
Here is some usefull sample of the code:
public class EplfColor
{
public int eplfColorId{ get; set; }
public string eplfColorName { get; set; }
public int eplfColorCode { get; set; }
public override string ToString()
{
return this.eplfColorName;
}
}
private void RefreshDGV()
{
combocolumn.DataSource = SitacController.GetEplfColor();
this.DGV_SITAC.DataSource = SitacController.GetAllSitac();
}
Extract of the Visual Studio Designer:
//
// EPLF_Color
//
EPLF_Color.DataPropertyName = "EplfColor";
EPLF_Color.DataSource = eplfColorBindingSource;
EPLF_Color.DisplayMember = "eplfColorName";
EPLF_Color.HeaderText = "EPLF Color";
EPLF_Color.MinimumWidth = 6;
EPLF_Color.Name = "EPLF_Color";
EPLF_Color.Resizable = DataGridViewTriState.True;
EPLF_Color.SortMode = DataGridViewColumnSortMode.Automatic;
EPLF_Color.ValueMember = "eplfColorId";
//
// eplfColorBindingSource
//
eplfColorBindingSource.DataSource = typeof(Models.EplfColor);
I was expecting the cell value to change.