Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > setting default value to DataGridViewComboBoxCell
 

setting default value to DataGridViewComboBoxCell

I linked some data to a datagridviewcomboboxcolumn via the designer , the problem is that when i display it, no default value is displayed, i want to display a default value for each cell, i tried with displaymember property of the DataGridViewComboBoxcell class in the constructor of the form, but i get an error. I dont know whats the property i have to change an in what eventhandler i must do it.
Thanks for your help!
andresvite  Tuesday, August 11, 2009 5:47 PM
You need to set the DataPropertyName property to the name of the field in your row.

Hope this helps.
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Tuesday, August 11, 2009 6:26 PM
i did what you say but, the problem still, i think datapropertyname doesn´t solve my problem. The combobox list all the values i want but the defaul value, is null, i must choose a value to change that. I just want to put the display default value manually. I think you get a better idea if i put an image but i cant.
Thanks!
andresvite  Thursday, August 13, 2009 12:21 AM
i put an image in my avatar so i hope it can help you undestand my problem
andresvite  Thursday, August 13, 2009 12:29 AM
Hi andresvite,

I am sorry to say DataGridViewComboBoxColumn doesn't offer default value property. Do you use data binding in your application?

If you use databinding, you can put a loop statement to set each datatable cell with a default value.

If you do not use databinding, you can put a loop to set each dataGridView cell with a default value.

Hope this helps you.
If you have any question, please feel free to tell me.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Thursday, August 13, 2009 2:53 AM
We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post editor window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Tuesday, August 18, 2009 7:58 AM

You can use google to search for other answers

Custom Search

More Threads

• auto completition grid cell
• BLOB binding to Image Column in DataGridView - What am I doing wrong?
• Problem with loading form with databound datagrid
• Can the DataGridView background color be changed for searched text?
• Click Delete button on dataBindingNavigator
• Displaying nested children elements in DataGridView
• DataGridView ComboBox Populating
• Creating an object from a row in a DataGridView / BindingSource
• Get error only when i add extended properties HDR=Yes to connection string
• Handling identity columns in a data bound GridDataView