Master
Master

Reputation: 2153

How can I Initialize IList

So my datagrid is populated with a Ilist

public IList SelectedItem2 { get; set; }

I have a double click action where I want to interact with the row value selected at index zero.

<telerik:RadGridView SelectedItem="{Binding SelectedItem2}" ItemsSource="{Binding AllQueries, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="True">
    <telerik:RadGridView.RowStyle>
        <Style TargetType="telerik:GridViewRow">
              <Setter Property="cal:Message.Attach" Value="[Event MouseDoubleClick] = [Open2()]"/>
        </Style>
    </telerik:RadGridView.RowStyle>
</telerik:RadGridView>

When I do double click on the row this error is produced. error produced Object reference not set to an instance of an object.

I'm Wondering how do i fix this error, normally in the ViewModel I would do something like

SelectedItem2 = new IList(); 

But there's no such thing :s

Within Open2

 Interaction i;
 IRecord vm;
 using (var ctx = DB.Get()) i = ctx.Interactions.Find(SelectedItem2.IndexOf(0))

Upvotes: 0

Views: 13102

Answers (5)

Ganesh Anthati
Ganesh Anthati

Reputation: 65

Ilist is an interface u should use list to instantiate.

SelectedItem2 = new List(); 

Upvotes: 0

user3147515
user3147515

Reputation: 59

IList is an interface. You can't instantiate interfaces. Use a concrete implementation of IList (such as SelectedItem2 = new List(), not IList).

Upvotes: 1

ps2goat
ps2goat

Reputation: 8475

You cannot initialize an interface. You need to create an object that implements that interface:

SelectedItem2 = new ArrayList(); 

Or

SelectedItem2 = new List(of object);

I'd prefer to use a type if all your values are the same type:

IList(Of string) SelectedItem2;
SelectedItem2 = new List(of string);

Upvotes: 5

D Stanley
D Stanley

Reputation: 152566

You need to use a class that implements IList, like List<T> (where T is the type of object the list can contain) or ArrayList

Upvotes: 2

Mez
Mez

Reputation: 4726

Check this link out http://social.msdn.microsoft.com/Forums/en-US/a30c4f18-eb14-4aa9-948f-701bb04b591e/list-initialization. You cannot initialise an interface. So you would do:

SelectedItem2 = new List(); 

Upvotes: 0

Related Questions