Use static class as datasource

Nest

I have static class which contains data, i wish to use static class as datasource in datagridview.

But datasource property only accepts object. How can i set static class as datasource?

Mike Perrenoud

You can't. But you could make it a Singleton:

public class MyClass
{
    private static MyClass _instance;
    public static MyClass Instance
    {
        get
        {
            if (_instance == null) { _instance = new MyClass(); }
            return _instance;
        }
    }

    private MyClass() { }
}

and then reference it like MyClass.Instance for the data source.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Use a static or a non static class

From Dev

Use static class by interface?

From Java

Use dependency injection in static class

From Dev

When to use static and class methods

From Dev

How use getFragmentManager() in static class

From Dev

Use of static collections within a class to store class

From Dev

Is there a workaround to use static methods by a generic class?

From Dev

understanding a final static use on a map field of a class

From Dev

How to use IHttpContextAccessor in static class to set cookies

From Dev

How to use static abstract class as a callback in Java?

From Dev

Instantiate a class to call a method or use static methods?

From Dev

Is it necessary to use static method and property in this class?

From Dev

Is there a workaround to use static methods by a generic class?

From Dev

How to initialize and make use of a static class?

From Dev

when to use static method or simple class method?

From Dev

How to use static abstract class as a callback in Java?

From Dev

how to use class static variable across files

From Dev

Can I use static class in business logic?

From Dev

Static variable and memory allocation in class and its use

From Dev

Virtual Method in a Base class to use a Static variable from a child class

From Dev

Java: Use Static methods of Parent Class in Child Class

From Dev

Java: Use Static methods of Parent Class in Child Class

From Dev

Use grails plugin datasource

From Dev

Static class with static properties

From Dev

XPages Java Class Instantiation as DataSource

From Dev

Closing DataSource if supplied to Jdbc class

From Dev

Is it safe to use static methods on File class in C#?

From Dev

Can I use static method from a different class?

From Dev

Referencing class without name to use different static method in subclasses in TypeScript

Related Related

  1. 1

    Use a static or a non static class

  2. 2

    Use static class by interface?

  3. 3

    Use dependency injection in static class

  4. 4

    When to use static and class methods

  5. 5

    How use getFragmentManager() in static class

  6. 6

    Use of static collections within a class to store class

  7. 7

    Is there a workaround to use static methods by a generic class?

  8. 8

    understanding a final static use on a map field of a class

  9. 9

    How to use IHttpContextAccessor in static class to set cookies

  10. 10

    How to use static abstract class as a callback in Java?

  11. 11

    Instantiate a class to call a method or use static methods?

  12. 12

    Is it necessary to use static method and property in this class?

  13. 13

    Is there a workaround to use static methods by a generic class?

  14. 14

    How to initialize and make use of a static class?

  15. 15

    when to use static method or simple class method?

  16. 16

    How to use static abstract class as a callback in Java?

  17. 17

    how to use class static variable across files

  18. 18

    Can I use static class in business logic?

  19. 19

    Static variable and memory allocation in class and its use

  20. 20

    Virtual Method in a Base class to use a Static variable from a child class

  21. 21

    Java: Use Static methods of Parent Class in Child Class

  22. 22

    Java: Use Static methods of Parent Class in Child Class

  23. 23

    Use grails plugin datasource

  24. 24

    Static class with static properties

  25. 25

    XPages Java Class Instantiation as DataSource

  26. 26

    Closing DataSource if supplied to Jdbc class

  27. 27

    Is it safe to use static methods on File class in C#?

  28. 28

    Can I use static method from a different class?

  29. 29

    Referencing class without name to use different static method in subclasses in TypeScript

HotTag

Archive