mysql - Trying to separate 2 items in a column for listview wpf -


i quite newbie wpf...any appreciated. started small project listview displays content mysql. far had no problems except column has 2 items in it. need separate each item in own column. easy date , time 1 beyond skills.

the display of listview (i can't post images yet):

date |time |callerid |from|to |duration

10 june 2015 |22:45|"alex" <210555555>|101 |201|234

the callerid column contains 2 values distinct "" , <>. need separate did date , time. help.

  <listview x:name="datalist" grid.column="1" grid.row="4"  itemssource="{binding path=ds}" background="white" foreground="black" fontsize="16" grid.columnspan="4" fontfamily="segoe ui" margin="1,0,8,0">         <listview.view>             <gridview allowscolumnreorder="false">                 <gridviewcolumn header="date" displaymemberbinding="{binding path=calldate,stringformat={}{0:dd mmmm yyyy}}"/>                 <gridviewcolumn header="time" displaymemberbinding="{binding path=calldate,stringformat={}{0:hh:mm:ss}}"/>                 <gridviewcolumn header="callerid" displaymemberbinding="{binding path=clid}"/>                 <gridviewcolumn header="from" displaymemberbinding="{binding path=src}"/>                 <gridviewcolumn header="to" displaymemberbinding="{binding path=dst}"/>                 <gridviewcolumn header="duration"  displaymemberbinding="{binding duration}" />             </gridview>         </listview.view>     </listview>  private void onload(object sender, routedeventargs e)         {         string cs = @"server=192.168.1.123;userid=alex;         password=r3s3ll3r;database=asteriskcdrdb";          mysqlconnection conn = null;         mysqldatareader rdr = null;          try             {             conn = new mysqlconnection(cs);             conn.open();              string stm = "(select * cdr order uniqueid desc limit 1000)";             mysqldataadapter = new mysqldataadapter(stm, cs);             mysqldataadapter.fill(ds);             datalist.itemssource = ds.defaultview;              }         catch (mysqlexception ex)             {             messagebox.show("error: {0}", ex.tostring());              }                     {             if (rdr != null)                 {                 rdr.close();                 }              if (conn != null)                 {                 conn.close();                 }              }         } 

consider moving towards more complete view model approach. instead of binding itemssource datatable.defaultview directly, create collection of view models define presentation logic each entry. example, define view model class such as

public class phonecallviewmodel {   public date calldate { get; set; }   public string callerid { get; set; }   // .... expose properties each column } 

this open lot of options dealing current problem. example, how split caller id string? create view model, such following

public class calleridviewmodel {   public string callername { get; set; }   public string callernumber { get; set; } } 

then phonecallviewmodel expose calleridviewmodel property. in onload method, create collection of these phonecallviewmodel objects (preferably observablecollection) , bind itemssource it. replace existing caller id column in listview 2 new columns. 1 bound callerid.callername, , second bound callerid.callernumber (assuming property on phonecallviewmodel named callerid).

i've left out details of splitting original caller id instantiating collection, separate implementation problems.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -