c# - Populating ListBox/View with just one item -


i have listbox (or listview) populate, list ever contains 1 item this: (it derived job class)

enter image description here

so listbox have 2 columns, 1 key, , 1 value, , row each key/value pair.

i cant seem work out how collection of 1 item, rather many items.

edit: have job class, has been auto generated linq. partial exmaple code:

public partial class job : inotifypropertychanging, inotifypropertychanged {  private int _id;   private string _hostname;   [global::system.data.linq.mapping.columnattribute(storage="_id", dbtype="int not null", isprimarykey=true)]     public int id     {                 {             return this._id;         }         set         {             if ((this._id != value))             {                 this.onidchanging(value);                 this.sendpropertychanging();                 this._id = value;                 this.sendpropertychanged("id");                 this.onidchanged();             }         }     }       [global::system.data.linq.mapping.columnattribute(storage="_hostname", dbtype="nvarchar(50)")]     public string hostname     {                 {             return this._hostname;         }         set         {             if ((this._hostname != value))             {                 this.onhostnamechanging(value);                 this.sendpropertychanging();                 this._hostname = value;                 this.sendpropertychanged("hostname");                 this.onhostnamechanged();             }         }     } } 

binding list of items listview pretty straightforward , easy do. example, should give basic idea on how display values want.

if have defined listview in xaml this:

<listview name="listviewjobs">     <listview.view>         <gridview>            <gridviewcolumn header="key" displaymemberbinding="{binding path=jobkey}" />            <gridviewcolumn header="value" displaymemberbinding="{binding path=jobvalue}" />        </gridview>     </listview.view> </listview> 

and class job has properties binding listview columns (in case jobkey , jobvalue properties):

public class job {     private string jobkey;     private string jobvalue;      // key property displayed      public string jobkey     {         { return jobkey; }         set { jobkey = value; }     }      // value property displayed     public string jobvalue     {         { return jobvalue; }         set { jobvalue = value; }     }      public job(string jobkey, string jobvalue)     {         this.jobkey = jobkey;         this.jobvalue = jobvalue;     } } 

to display list of jobs in listview need this:

// create new list list<job> listjob = new list<job>(); // create new job , add list job newjob = new job("examplekey", "examplevalue"); listjob.add(newjob);  // set list source our listview listviewjobs.itemssource = listjob; 

binding take care of linking columns properties class , display selected values items add source list.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -