c# - Populating a UIPickerView with data from Sqlite DataBase in IPhone App -- -
i have sqlite database table 'bikeinfo'
[bikeid, bikename]
now want pickerview populated names of bikes database. in .net easy. being complete beginner in monotouch, have got no clue how approach problem. did googling , found out have create kind of custom class extending uipickerviewmodel
class , override various methods. that's it. not find sample code, tutorial or anything. have been battling 3 days now. totally confused. far have written function fetching data table , returning list of class objects[that have written containing properties bikename , bikeid]. maybe looking in wrong places. need done ever way.
any kind of tutorial, or sample code in c# dealing target-specific scenario helpful me.
the next objective show alert message showing corresponding bike id when user touches 1 particular item. think have define selected event in custom class. have picked internet.
thanks.
this have done far. have created class containing properties bikeid
, bikename
.
namespace astonapp { public class pickerfacilitytemplate { public pickerfacilitytemplate () { } public int bikeid{get; set;} public string bikename{get; set;} } }
after have written function in database handler class returns list of class objects of above class type.
public list<pickerfacilitytemplate> fetchfacility() { dataset ds = new dataset (); string sql = "select * bikeinfo order bikename"; this.createdbconnection (); sqlitedataadapter sda = new sqlitedataadapter (sql, sconn); sda.fill (ds); list<pickerfacilitytemplate> objfcl=new list<pickerfacilitytemplate>(); for(int i=0; i<ds.tables[0].rows.count; i++) { pickerfacilitytemplate pft=new pickerfacilitytemplate(); pft.bikeid=convert.toint32(ds.tables[0].rows[i]["bikeid"].tostring()); pft.bikename=ds.tables[0].rows[i]["bikename"].tostring (); objfcl.add (pft); } this.closedbconnection (); return objfcl.tolist (); } public class pickerdatamodelsource: uipickerviewmodel { public pickerdatamodelsource () { } public pickerdatamodelsource (list<pickerfacilitytemplate> lst) { this.items=lst; } public event eventhandler<eventargs> valuechanged; public list<pickerfacilitytemplate> items; list<pickerfacilitytemplate> _items = new list<pickerfacilitytemplate>(); public pickerfacilitytemplate selecteditem { { return this._items[this._selectedindex]; } } public int _selectedindex = 0; public override int getrowsincomponent (uipickerview picker, int component) { return this._items.count; } public override string gettitle (uipickerview picker, int row, int component) { return items[row].bikename.tostring(); } public override int getcomponentcount (uipickerview picker) { return 1; } public override void selected(uipickerview picker, int row, int component) { this._selectedindex = row; if (this.valuechanged != null) { this.valuechanged (this, new eventargs ()); } } }
now in class file of screen have pickerview, have written,
pickerdatamodelsource _pickersource;
and in viewdidload
method:
this.picker.source=this._pickersource; this.picker.model=this._pickersource;
but when run application, pickerview blank. missing something? error in logic?
thanks.
one example of how use picker in "kitchen sink" sample - https://github.com/xamarin/monotouch-samples/tree/master/monocatalog-monodevelop - in https://github.com/xamarin/monotouch-samples/blob/master/monocatalog-monodevelop/pickerviewcontroller.xib.cs
in general, find repo essential lots of mt dev tasks.
Comments
Post a Comment