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

  • Home
  • SEARCH
  • 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 3243930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:29:28+00:00 2026-05-17T18:29:28+00:00

I have dynamically created DataGridView control on form, with DataSource specified as: ((DataGridView)createdControl).DataSource =

  • 0

I have dynamically created DataGridView control on form, with DataSource specified as:

    ((DataGridView)createdControl).DataSource = (IList)(p.GetValue(editedClient, null));

where IList is defined as generic collection for following class:

     public class CDocumentOperation

   {
        [DisplayName(@"Time")] 
        public DateTime TimePosted { get; set; }
        [DisplayName(@"User")]
        public CUser User { get; set; }
        [DisplayName(@"Action")]
        public string Action { get; set; }
    }

grid is populated successfully with data, but the only problem that all columns
are created as Text fields.What I need is to manually convert column
which binds to User field, to have Buttons or Links (convert column type to DataGridViewButtonColumn).

Can I do this, without modifying grid auto-fill on grid post creation, without manual
column creation of appropriate type and data copying ?

  • 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-17T18:29:28+00:00Added an answer on May 17, 2026 at 6:29 pm

    The short answer is that this cannot be done without manually creating the columns (and setting the DataPropertyName property) before binding. There is no attribute you can use to decorate your data source, the DataGridView will simply generate a DataGridViewTextBoxColumn for every data type (except Boolean which it will resolve to a checkbox column). This behaviour is internal and unchangeable.

    Your best bet is to disable AutoGenerateColumns on the grid and write your own method that dynamically generates appropriate column types, perhaps based on your own custom attribute, such as (from your example above):

    [DisplayName(@"Time"), ColumnType(typeof(DataGridViewButtonColumn))] 
    public DateTime TimePosted { get; set; }
    

    The attribute class is easy to write (just extend Attribute, add a Type field and an appropriate constructor). In the method that will generate the columns (immediately before binding), you can use reflection to crawl for properties and check for the presence of the custom attribute. (BindingSource.GetItemProperties() is very useful for obtaining information about the properties on objects in a collection.)

    This is not the most elegant solution (and it delves into some intermediate-level concepts), but it’s the only way to get around this limitation with auto-generated columns in the DataGridView control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dynamically created DataGridView that has a valid DataSource with one row
I have created a form with a dynamically created field and i am trying
I have dynamically created a xml string form a JSON object returned from server.
I have a dynamically created Image control that is populated via a OpenFileDialog like:
I have dynamically created the buttons in a div. And binding the click and
I have dynamically created some list of RadioButtons with some values. pro grammatically I
I have dynamically created WrapPanel (_wp) with several Borders. And I need create handler
I am going to make a GUI that will have dynamically created sets of
I have a dynamically created list. Items from the list should be able to
I have a dynamically created table which in the last <td> there is 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.