This is on .Net 2.0 in a WinForms application.
I have a DataGridView that is bound to a BindingSource. The
DataGridView has 3 columns. The first two are "normal" text columns and
the last is a combo box column.
Data binding is working fine for the first two columns. I am able to
edit values and persist them back to the bound object and ultimately
back to the database.
Data binding for the combo box column only shows the current value. I
cannot change it.
Here is the code for creating the combo box column:
DataGridViewComboBoxColumn dgvcQuantityUom =
new DataGridViewComboBoxColumn();
dgvcQuantityUom.Name = "QuantityUom";
dgvcQuantityUom.DataPropertyName = "QuantityUom";
dgvcQuantityUom.HeaderText = "Uom";
dgvcQuantityUom.DataSource = _uomList;
dgvcQuantityUom.DisplayMember = "UomName";
So, this column is bound to the property "QuantityUom". That property
is of the type "Uom" (Unit of Measure).
_uomList is an IList<Uom> of Uom objects. This is the drop down list
for the combo box.
---
When I do databinding for "normal" comob box controls outside of a
datagrid, I have a line that sets up the databinding:
myComboBox.DataBindings.Add("SelectedItem", myDataBindingSource,
"NameOfProperty");
But I don't see how I can get to the databindings for the DataGridView's
combo box.
Any ideas??
Brian
Hi Brian,
Thank you for posting here!
I notice that you have posted the same question in our
microsoft.public.dotnet.languages.csharp newsgroup, which I have already
responded. So please check my answer there and if you need any further
assistance on this particular issue, please reply to me in that thread so I
can follow up with you in time.
For your convenience, I have included my reply as follows:
============================================================
> So, this column is bound to the property "QuantityUom". That property is
of the type "Uom" (Unit of Measure).
Do you mean that the QuantityUom property which is bound to the
DataGridView combobox column is of a complex type 'Uom'? Generally
speaking, we bind a property of a simple type to a DataGridView combobox
column.
I noticed that you don't set the ValueMember property of the
DataGridViewComboBoxColumn. If you have set the DataPropertyName property
of the DataGridView combobox column, you should set the DataSource,
DisplayMember and ValueMember properties all.
If the problem is still not resolved, you may send me your sample project
that could just reproduce the problem. To get my actual email address,
remove 'online' from my displayed email address.
==============================================================
Thank you and have a nice day!
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.