Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7171377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:24:10+00:00 2026-05-28T15:24:10+00:00

I have a GUI which allows the user to select a report to view/edit.

  • 0

I have a GUI which allows the user to select a report to view/edit. When the user selects a report, it shows the Items in the report. The Item has many properties – most of which are binding properly. One of the properties is Owner, and this is bound to a ComboBoxColumn.

  • Report
    • Items
      • Owner

I have done something very similar to this a few times and had no problems when I set the DataPropertyName, DataSource, ValueMember, and DisplayMember. The only difference is that this time instead of the Item type having an OwnderID it actually has an instance of the Owner object.

I saw a suggestion on another post to solve this issue by giving the items bound in the list a self-referencing property that allows them to return themselves for the purposes of setting the ValueMember

However, When I bind it this way:

OwnerColumn.DataPropertyName = "Owner"
OwnerColumn.DataSource = ownersBindingSource1
OwnerColumn.ValueMember = "Self"
OwnerColumn.DisplayMember = "OwnerName"

I get a lot of errors like:

Unable to cast object of type 'System.String' to type 'Owner'.

and:

The following exception occurred in the DataGridView:

System.ArgumentException: DataGridViewComboBoxCell value is not valid.

To replace this default dialog please handle the DataError event.

I was able to get around some of these errors by binding it like this:

OwnerColumn.DataPropertyName = "Owner"
OwnerColumn.DataSource = ownersBindingSource1

and also by making the ToString function on the Owner display the OwnerName property. This seems pretty hacky though – and I think I’m misunderstanding something fundamental as it still does not function properly. Any help would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:24:11+00:00Added an answer on May 28, 2026 at 3:24 pm

    I found out that a lot of my errors were coming from my misunderstanding of various articles I had read, as well as sloppy code.

    I neglected to specify the return type on a few of the properties, option explicit / option strict were both off, and there had been some corruption in my designer and a few of the columns were duplicated.

    A solution to this that I liked the most was: http://code.google.com/p/systembusinessobjects/source/browse/trunk/System.BusinessObjects.Framework/Data/SafeBindingLists.cs . Unfortunately, this requires Castle proxy, and an older version of NHibernate.

    Here is the simple solution that I found:

    The issue is that you cannot bind a list with objects of multiple types. The goal is to be able to have the ComboBox directly set the value of a property on the object it is bound to with another object.

    I chose to use a View object, and bind the list to that.

    View Object:

    Public Class OwnerView
        Private _owner As Owner
    
        Public ReadOnly Property OwnerId As Integer
            Get
                Return _owner.OwnerId
            End Get
        End Property
    
        Public ReadOnly Property OwnerName As String
            Get
                Return _owner.OwnerName
            End Get
        End Property
    
        Public ReadOnly Property OwnerAbbreviation As String
            Get
                Return _owner.OwnerAbbreviation
            End Get
        End Property
    
        Public Overridable ReadOnly Property Self As Owner
            Get
                Return _owner
            End Get
        End Property
    
        Public Sub New(ByVal owner As Owner)
            _owner = owner
        End Sub
    
    End Class
    

    Binding:

    With OwnerColumn
        .SortMode = DataGridViewColumnSortMode.Automatic
        .ReadOnly = False
        .Name = "OwnerColumn"
        .HeaderText = "Owner"
    
        Dim bs As New BindingSource()
    
        For Each co As Owner In Owners
            bs.Add(New OwnerView(co))
        Next
    
        .DataPropertyName = "Owner"
        .DataSource = bs
        .ValueMember = "Self"
        .DisplayMember = "OwnerName"
    
        ItemDataGridView.Columns.Add(OwnerColumn)
    End With
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GUI app written in C++/CLI which has a load of configurable
I have designed this gui in netBeans which has a canvas , a couple
I have a GUI which has a couple of checkboxes that control special modes
I have designed a GUI which has an uitable and a push button which,
I have an unhandled exception handler. It shows a nice GUI and allows users
I have a Flex GUI which is using AMF Streaming to BlazeDS on WebLogic
I have 2 projects. One project is a core and contains the GUI which
I have a win32 GUI (MFC) application which I need to port to a
i have this GUI screen shots from the design team which i needs to
I have a GUI program, which would call a cmd in this GUI program.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.