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 General / February 2007

Tip: Looking for answers? Try searching our database.

Frustrating problem with DatGridView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Barry Gilbert - 06 Feb 2007 20:12 GMT
I have a DatagridView bound to a bindingsource. I programmatically add a
ComboboxColumn and bind it to another BindingSource like this:

           Dim colActType As New DataGridViewComboBoxColumn
           colActType.DataSource = ActivityTypesBindingSource
           colActType.HeaderText = "Activity Type"
           colActType.DataPropertyName = "ActivityTypeId"
           colActType.ValueMember = "Id"
           colActType.DisplayMember = "Descr"
           DataGridView1.Columns.Add(colActType)

The values behave as expected. The displayed values in the Combobox
correctly display the value from the Descr field. Changing the value saves
correctly to the main table. The problem is that when the DataGridView
displays, the Combobox column displays the value in the ValueMember field.
When I click in the combobox, it shows the DisplayMember value, but reverts
back when I click or tab away.

Any thoughts would be helpful.

Barry

PS: Apologies if this message posts twice. I'm not sure why that is
happening here.
Barry Gilbert - 06 Feb 2007 20:32 GMT
Resolved!

For posterity, here's what was going on:
The data types of the Value Member and the DataPropertyName fields did not
match. One was a Byte and the other an Integer. This caused a formatting
exception when populating the DataGridView. I couyldn't find a solution to
this originally, so I trapped it and let it die. The unfortunate side-effect
was that the Value Member value was being displayed in the column instead of
the Display Member value.

All is well, oh my children, and it only cost me two days and a lot of
heartache.

Barry

> I have a DatagridView bound to a bindingsource. I programmatically add a
> ComboboxColumn and bind it to another BindingSource like this:
[quoted text clipped - 20 lines]
> PS: Apologies if this message posts twice. I'm not sure why that is
> happening here.

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.