Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / January 2007

Tip: Looking for answers? Try searching our database.

DataGridView and ComboBoxColumn

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Pelton - 30 Jan 2007 22:13 GMT
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
Linda Liu [MSFT] - 31 Jan 2007 06:46 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.