WPF Accessing subitems in a ListView/GridView -


i'm attempting access listview subitem. have insert columns listview/gridview dynamically program accesses multiple databases different value types. if need be can portion out database searching multiple tabs, ease of use, i'd rather not take route.

i've been searching 3-4 days solution. class organizes subitems data oledb query. here snippet of code i'm using:

    public class repair     {         public string rp { get; set; }         public string sn { get; set; }         public datetime rec { get; set; }         public datetime start { get; set; }         public string cust { get; set; }         public string sp { get; set; }         public string tech { get; set; }         public string status { get; set; }         public string model { get; set; }         public string notes { get; set; }         public datetime accused { get; set; }         public string accnotes { get; set; }         public int id { get; set; }     }     public ilist<repair> openrepair { get; set; } 

it inserts data listview following snippet:

var gridview = new gridview(); this.searchlistview.view = gridview; gridview.columns.add(new gridviewcolumn { header = "rma #", displaymemberbinding = new system.windows.data.binding("rp") }); gridview.columns.add(new gridviewcolumn { header = "serial", displaymemberbinding = new system.windows.data.binding("sn") }); gridview.columns.add(new gridviewcolumn { header = "recieved", displaymemberbinding = new system.windows.data.binding("rec") }); gridview.columns.add(new gridviewcolumn { header = "start", displaymemberbinding = new system.windows.data.binding("start") }); gridview.columns.add(new gridviewcolumn { header = "customer", displaymemberbinding = new system.windows.data.binding("cust") }); gridview.columns.add(new gridviewcolumn { header = "sales person", displaymemberbinding = new system.windows.data.binding("sp") }); gridview.columns.add(new gridviewcolumn { header = "technician", displaymemberbinding = new system.windows.data.binding("tech") }); gridview.columns.add(new gridviewcolumn { header = "status", displaymemberbinding = new system.windows.data.binding("status") }); gridview.columns.add(new gridviewcolumn { header = "repair notes", displaymemberbinding = new system.windows.data.binding("notes") }); gridview.columns.add(new gridviewcolumn { header = "accidental used date", displaymemberbinding = new system.windows.data.binding("accused") }); gridview.columns.add(new gridviewcolumn { header = "accidental notes", displaymemberbinding = new system.windows.data.binding("accnotes") }); gridview.columns.add(new gridviewcolumn { header = "id", displaymemberbinding = new system.windows.data.binding("id"), width = 0 }); using (oledbconnection cn = new oledbconnection(@"provider=microsoft.ace.oledb.12.0;data source=x:\***")) {     cmd.connection = cn;     cmd.commandtext = sqlstatement;     try     {          cn.open();          dr = cmd.executereader();          if (dr.hasrows)          {              while (dr.read())              {                   openrepair = new list<repair>();                   if (dr[10].tostring() == "true")                   {                         openrepair.add(                         new repair()                         {                            rp = dr[0].tostring(),                            sn = dr[1].tostring(),                            rec = convert.todatetime(dr[2].tostring()).date,                            start = convert.todatetime(dr[3].tostring()).date,                            cust = dr[4].tostring(),                            sp = dr[5].tostring(),                            tech = dr[6].tostring(),                            status = dr[7].tostring(),                            model = dr[8].tostring(),                            notes = dr[9].tostring(),                            accused = convert.todatetime(dr[11].tostring()),                            accnotes = dr[12].tostring(),                            id = convert.toint32(dr[13].tostring())                         });                     }                     else                     {                          openrepair.add(                          new repair()                          {                              rp = dr[0].tostring(),                              sn = dr[1].tostring(),                              rec = convert.todatetime(dr[2].tostring()).date,                              start = convert.todatetime(dr[3].tostring()).date,                              cust = dr[4].tostring(),                              sp = dr[5].tostring(),                              tech = dr[6].tostring(),                              status = dr[7].tostring(),                              model = dr[8].tostring(),                              notes = dr[9].tostring(),                              id = convert.toint32(dr[13].tostring())                           });                       }                   searchlistview.items.add(openrepair);                } 

the xaml behind listview:

<listview itemssource="{binding repair}" selectionmode="single" x:name="searchlistview" margin="0,63,0,0" background="darkgray" mousedoubleclick="searchlistview_mousedoubleclick">                     <listview.view>                         <gridview />                     </listview.view>                 </listview> 

i've attempted grab subitem values within listview/gridview few approaches. has not been successful on either of these codes:

                repair lvi = (repair)searchlistview.selecteditems[0];                 system.windows.messagebox.show(lvi.rp + " " + lvi.sn + " " + lvi.sp); 

&

          repair lvi = (repair)this.customerslistview.selecteditem;           messagebox.show(string.format("repair: {1}{0}serial number:{2}", environment.newline, lvi.rp, lvi.sn)); 

even attempted windows form approach, did not work.

could please @ least point me in correct direction? error message i've been obtaining makes sense being cannot cast object generic list class repair, however, since new wpf, i'm stumped on how passed message!

following comment, here more complete answer, future reference.

the selected object (the 1 displayed selecteditem) available through selectedvalue.

and use list should following:

((list<repair>)searchlistview.selectedvalue)[0].sn 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -