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 8616619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:39:45+00:00 2026-06-12T05:39:45+00:00

I have a Many to Many mixed with some Master-Detail DataGrid setup. 4 DataGridView

  • 0

I have a Many to Many mixed with some Master-Detail DataGrid setup.

  • 4 DataGridView
  • 6 Entities (2 mapping tables)
  • 5 Data relations

To give you a visual image, there is 1 big Employe DGV (DataGridView), and 3 smaller ones which updates depending on the Employe DGV selected row.

One of the 3 smaller grid is a really simple relation without a mapping table.

The other 2, however, displays a mapping table rows that uses formatedinfo of the entity it is mapping to. Those 2 DGV only have 1 column, a ComboBox with a formated string (overriden .ToString()) which (should) have the underlying object that the mapping is pointing to (EF will handle setting the ID accordingly when receiving the entire object). However, when I try to add a new rows, it will say it is unable to convert a String to a Put Object Name Here. This led me to think that if you did not set a ValueMember, the combobox would try to get a string representation using .ToString(). So I attempted to bypass that behavior by adding a Self property to the entity which simply returns himself. No success, it is still trying to convert a string somewhere.

The exact error (in french) is:

System.FormatException: Cast non valide de 'System.String' en 'InvInformatique.logiciels'.

Which traducts to “Invalid cast from System.String to InvInformatique.logiciels.

Code

InventaireInformatiqueEntities iidb = new InventaireInformatiqueEntities();

bsEmployes.DataSource = iidb.employes;
bsMateriels.DataSource = iidb.materiels;
bsLogiciels.DataSource = iidb.logiciels;
bsLogicielEmployeMaps.DataSource = iidb.logiciel_employe_maps; // Needed to provoke the load query
bsAcces.DataSource = iidb.acces;
bsAccesEmployeMaps.DataSource = iidb.acces_employe_maps; // Needed to provoke the load query

dgvEmployes.AutoGenerateColumns = false;
dgvEmployes.Columns.AddRange(
    new DataGridViewTextBoxColumn { Name = "Nom", DataPropertyName = "nom" },
    new DataGridViewTextBoxColumn { Name = "Département", DataPropertyName = "departement" }
);
dgvEmployeMateriels.AutoGenerateColumns = false;
dgvEmployeMateriels.Columns.AddRange(
    new DataGridViewTextBoxColumn { HeaderText = "Nom", DataPropertyName = "nom" },
    new DataGridViewTextBoxColumn { HeaderText = "Satisfaction", Name = "satisfaction", DataPropertyName = "satisfaction" }
);
dgvEmployeAcces.AutoGenerateColumns = false;
dgvEmployeAcces.Columns.AddRange(
    new DataGridViewComboBoxColumn { HeaderText = "Accès", DataPropertyName = "acces", DataSource = bsAcces }
);
dgvEmployeLogiciel.AutoGenerateColumns = false;
dgvEmployeLogiciel.Columns.AddRange(
    new DataGridViewComboBoxColumn { HeaderText = "Logiciels", DataPropertyName = "logiciels", DataSource = bsLogiciels }
);

dgvEmployes.DataSource = bsEmployes;
dgvEmployeMateriels.DataBindings.Add(new Binding("DataSource", bsEmployes, "materiels"));
dgvEmployeLogiciel.DataBindings.Add(new Binding("DataSource", bsEmployes, "logiciel_employe_maps"));
dgvEmployeAcces.DataBindings.Add(new Binding("DataSource", bsEmployes, "acces_employe_maps"));

Database

Employes
->id
->nom
->departement

Acces
->id
->nom
->description

Logiciel
->id
->nom

Materiel
->id
->employe_id
->nom
->description

Acces_Employe_Maps
->id
->acces_id
->employe_id

Logiciel_Employe_Maps
->id
->logiciel_id
->employe_id

Database relations

Employes <-> Logiciel_Employe_Maps <-> Logiciels
Employes <-> Acces_Employe_Maps <-> Acces
Employes -> Materiel
  • 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-06-12T05:39:47+00:00Added an answer on June 12, 2026 at 5:39 am

    Ok so, DataGridViews don’t like using ToString() to get a DisplayMember. When I keep DisplayMember empty or use my Self property, it bugs out the ValueMember.

    Setting DisplayMember = "nom", ValueMember="Self" worked perfectly.

    Edit

    This also worked:

    Add to EF partial class:

    public string FormatedName { get { return this.ToString(); } }
    

    Change in column definition:

    DisplayMember = "FormatedName", ValueMember = "Self"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many sites under one ASP.NET forms authentication. They have mixed frameworks (some
I have many timestamp columns that I need to use with mixed timezones. The
I have a Web Application (C# pages mixed with ASP.NET and some Javascript pages)
First some background on the application. I have an application processing many independent tasks
I have a CakePHP Application with many many screens using data from a specific
I have many different NSArray 's stored in .dat files, in the Documents folder
I have many PowerPoint presentations that I need to be able to add to
I have many many files in a folder, and I want to process them
I have many directories with files in them. I want to create a comma
We have many projects with several files inside each. Files can be checked in

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.