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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:42:26+00:00 2026-05-27T02:42:26+00:00

In Winform application I have a class with 2 properties and I want the

  • 0

In Winform application I have a class with 2 properties and I want the user to be able to choose the type of those properties.

This is what I made so far:

Class with the properties:

static public class DataGridColumnData
{
    public static object SearchColumn { get; set; }
    public static object ResultColumn { get; set; }
}

And the user can choose the type of the properties using a Combobox with DropDownList Style which has values like

System.String
System.Double
System.Int32
System.Boolean
System.DateTime 

Is there a way to make those properties to be types the ones that user chooses?

  • 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-27T02:42:27+00:00Added an answer on May 27, 2026 at 2:42 am

    There are ways to make the properties strongly typed in runtime using generics, but I am not sure how useful it is. Here is a solution either way:

    Create an interface that is not strongly typed to facilitate interaction with the object:

    public interface IDataGridColumnData
    {
        object SearchColumnAsObject { get; set; }
        object ResultColumnAsObject { get; set; }
    }
    

    Create generic class that allows for the creation of strongly typed versions at runtime (and in code as well, of course), and that implements the interface:

    public class DataGridColumnData<TSearch, TResult> : IDataGridColumnData
    {
        public TSearch SearchColumn { get; set; }
        public static TResult ResultColumn { get; set; }
        public object SearchColumnAsObject
        {
            get { return SearchColumn; }
            set { SearchColumn = (TSearch)value; }
        }
        public object ResultColumnAsObject
        {
            get { return ResultColumn; }
            set { ResultColumn = (TResult)value; }
        }
    }
    

    Create a factory method that will manufacture strongly typed versions of the class, returning it as the object-typed interface:

    private static IDataGridColumnData GetDataGridColumnData(
        Type searchType, Type resultType)
    {
        var typedColumnDataType = typeof(DataGridColumnData<,>)
                .MakeGenericType(new[] { searchType, resultType });
        return (IDataGridColumnData)Activator.CreateInstance(typedColumnDataType);
    }
    

    …and put it to use:

    IDataGridColumnData instance = GetDataGridColumnData(
        Type.GetType("System.Int32"),
        Type.GetType("System.String"));
    
    // use the properties
    instance.SearchColumnAsObject = 42; // works well
    instance.SearchColumnAsObject = "42"; // throws exception
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume in a winform application we have in program.cs : static class Program {
I am using C# and developing a winform application. I have a project class
I have an application (winform exe) that I run several times. Does this mean
I following this article for sending SMS it is a winform application.. I have
In a WinForms application I'm working on I'd like to have a properties class
I have a problem with MouseEvents on my WinForm C# application. I want to
I have a winform application in C# .NET framework 2 which I want to
My WinForm application is configured like this: public class RepositoriesInstaller : IWindsorInstaller { public
I have a winform application made up of two assemblies : a business layer
I have a winform application (one form), on this form there is a RichTextBox.

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.