Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

I bounded combobox to the datagridview. This combobox takes its values from enum, like this:
C#
DataGridViewComboBoxColumn comboColumn = new DataGridViewComboBoxColumn();
comboColumn.DataSource = Enum.GetNames(typeof(Duration));
comboColumn.Name = "Duration";
comboColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
dataGrid.Columns.Add(comboColumn);


Now I need to select a default item for each of the combobox in the datagridview, but it's not necessary to be the same item to all the combobox. How could I do that?


Thanks in advance.
Posted
Updated 31-Jan-12 22:46pm
v2
Comments
Amir Mahfoozi 1-Feb-12 3:37am    
WPF ? ASP.NET ? WinForm ?

1 solution

You can use the DefaultCellStyle.NullValue and DefaultCellStyle.DataSourceNullValue properties of the combo box column. Code sample is:

C#
comboColumn.DefaultCellStyle.NullValue = "dataToStore";
comboColumn .DefaultCellStyle.DataSourceNullValue = "dataToStore";
 
Share this answer
 
Comments
Salah_Afa 1-Feb-12 4:42am    
I need to select different value for each combobox, not the same value for all the combobox.
Thanks
Ibrahim Islam 28-May-13 5:56am    
Thanks @GanesanSenthilvel you are a life saver

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900