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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:57:21+00:00 2026-05-16T08:57:21+00:00

I have problem with databinding in the Win.Forms DataGridView control. Example: public class A

  • 0

I have problem with databinding in the Win.Forms DataGridView control.
Example:

public class A
{
      public String Title {get; set; }
      public B BField { get; set; }
}

public class B
{
      public String Name { get; set; }
}

I want to see in my column value from B. (BField.Name).
I tried to use the next way for data key, just fill with BField.Name value, but it doesn’t work for me. Else I want to have opportunity for chaning this field value via DataGridView.

Also I tried to create:

class A 
{
...

       public String BField_Name 
       {
           get{return BField.Name;} 
           set{BField.Name = value;}
       }
}

But it doesn’t work too.
Can you help me to fix this problem?

Thanks!

With The Best Regards,
Alexander.

  • 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-16T08:57:22+00:00Added an answer on May 16, 2026 at 8:57 am

    To have the “B” class value show correctly in the Grid, override the ToString method to return the Title property.

    You can then create a TypeConvertor for the “B” class so the Grid knows how to translate the string cell value into a “B” class type, i.e.

       public class BStringConvertor : TypeConverter
       {
          public BStringConvertor()
             : base()
          {
          }
    
          public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
          {
             // Allow conversion from a String type
             if (sourceType == typeof(string))
                return true;
    
             return base.CanConvertFrom(context, sourceType);
          }
    
          public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
          {
             // If the source value is a String, convert it to the "B" class type
             if (value is string)
             {
                B item = new B();
                item.Title = value.ToString();
                return item;
             }
             return base.ConvertFrom(context, culture, value);
          }
    
          public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
          {
             // If the destination type is a String, convert the "B" class to a string
             if (destinationType == typeof(string))
                return value.ToString();
    
             return base.ConvertTo(context, culture, value, destinationType);
          }
       }
    

    Then you can apply the converter to the “B” class property of your “A” class, i.e.

       public class A
       {
          public string Title { get; set; }
    
          [TypeConverter(typeof(BStringConvertor))]
          public B BField { get; set; }
       }
    
       public class B
       {
          public string Title { get; set; }
    
          public override string ToString()
          {
             return this.Title;
          }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with a databinding. I have a class with properties to
I am trying set up databinding as described in the title. The problem I
I have a little databinding-problem. (I usually have...) This is the error I get
I have run into a problem w/ my model for databinding in WPF. I
I have problem developing with live555. I already build the lib-files and example projects
I have a databinding problem in WPF. I would like to customise a slider
I have a problem with a databinding in WPF. When I try to use
I am new to vaadin and have a databinding problem. I have posted allready
I have got a problem. I have windows forms application with dynamic generated layout,
I have a problem with performance of my code under Windows Forms. Have a

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.