Viraj Shah
Viraj Shah

Reputation: 308

ListPicker issue in Windows Phone

   long stdid;
    string stdname;


    public long studentId
    {
        get { return stdid; }
        set { stdid = value; }
    }

    public string studentName
    {
        get { return stdname; }
        set { stdname = value; }
    }

how do I show my listpikcer with by default selected item "SELECT", my listpicker is binded with,

ItemsSource = "{Binding}"

I have not added items manually in listpicker, items come from class, so, how to solve it?

Upvotes: 0

Views: 175

Answers (1)

A.K.
A.K.

Reputation: 3331

Create a new List of your class type

List<MyClass> myList=new List<MyClass>();

and add one item of your class type somewhat like this:

myList.Add(new MyClass(){studentName="Please Select, StudentId=0"});

now add the items of your class list in this new list

foreach(var item in oldList)
{
myList.add(item);
}

after this loop assign myList as the itemsource to the listpicker and check.

listpicker.ItemSource=myList;
listpicker.SelectedIndex=0;

Upvotes: 2

Related Questions