Hi David,
Based on my understanding, you want to display a dropdown list of items in
each Combobox of DataGridViewComboBoxColumn. If I have misunderstood you,
please feel free to tell me, thanks.
The programming model of DataGridViewComboBoxColumn can be found in the
link below, also, there is sample code in the link of populating the
combobox with a list of items:
http://msdn2.microsoft.com/en-us/lib...datagridviewco
mboboxcolumn.aspx
We can populate the dropdownlist of combobox in DataGridViewComboBoxColumn
with DataGridViewComboBoxColumn.Items property. Please refer to
SetAlternateChoicesUsingItems method in the above sample code.
The key point is that the items populated in the list must be correspond to
the datasource data value of DataPropertyName from DataGridView
databinding. The datasource data of DataPropertyName is used as the
SelectedValue property of the Combobox. The DataGridView databinding
requires looking up the value in the combobox items and getting the display
value for the item. During this process, if the cell's value cannot be
found in the combo box items collection it raises the DataError event.
Let's take the above sample code as an example:
In above DataGridView databinding, the DataGridView will display employees
table from northwind sample database.
DataGridViewComboBoxColumn.DataPropertyName is set to *TitleOfCourtesy*
field in CreateComboBoxColumn() method. So, to populate the
DataGridViewComboBoxColumn.Items property, we should take care to assign
items corresponding to the data of *TitleOfCourtesy* field, such as "Mr.",
"Ms.", "Mrs.", "Dr.". If we assign other data to the Items property instead
of above 4 candidate values, the databinding will fail to find a
selectedvalue in dropdownlist, and DataError event is raised.
Once you take care of this key point, you should can use
DataGridViewComboBoxColumn without any problem.
Additionally, Microsoft .Net Winform team has maintained a wonderful
DataGridView FAQ with samples in the link below. After you download it, in
the DataGridView FAQ, you will find a lot of guidelines regarding using
DataGridView, also a dedicated topic with DataGridViewComboBoxColumn in
section 3.5:
http://www.windowsforms.net/Samples/...mId=220&tabind
ex=4
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.