Jordy
Jordy

Reputation: 988

create Collection<T>

In my project I want to create my own DataGrid, but I don't know from which object I want to create the columns of.

So I want a property:

private List<T> DataSource

Someone who has any idea how to fix this?

Upvotes: 0

Views: 147

Answers (3)

HitLikeAHammer
HitLikeAHammer

Reputation: 2695

Look into IBindingList<T>. This interface is intended to be for lists that will be used in databinding. Your property should be of this type then, anything that implents this type can be used to bind to your grid.

Upvotes: 0

John Agan
John Agan

Reputation: 333

Why not just leave it as "object" and cast it?

Upvotes: -1

womp
womp

Reputation: 116977

You haven't provided very much code or explanation, but I'm guessing you're getting a compiler error on that line regarding the generic parameter. You'll need to make your class declaration generic to also accept a parameter T. Like this:

public class MyDataGridWrapper<T> : DataGrid
{

    private List<T> DataSource;
    ...
    ...

}

You haven't really specified what's wrong though, so I'm just guessing at both the error you're getting and what's actually wrong.

Upvotes: 2

Related Questions