Well I have reviewed my code blocks and removed off the needless parts. All I
am doing is, returning a list of class objects [the class containing the
properties I need] from my database handler function, written a custom class
extending the UIPickerViewModel class. 

So we have a class-->

namespace ASTONAPP
{
        public class PickerFacilityTemplate
        {
                public PickerFacilityTemplate ()
                {
                }

                public int AssessmentID{get; set;}
                public int FacilityID{get; set;}
                public string FacilityName{get; set;}
        }
}

My database handler function

public List<PickerFacilityTemplate> FetchFacility()
                {
                        DataSet ds = new DataSet ();
                        string sql = "select * from ClientFacilityorder by 
FacilityName";
                        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.AssessmentID=Convert.ToInt32(ds.Tables[0].Rows[i][&quot;AssessmentID&quot;].ToString
());                            
                               
pft.FacilityID=Convert.ToInt32(ds.Tables[0].Rows[i][&quot;FacilityID&quot;].ToString
()); 
                                
pft.FacilityName=ds.Tables[0].Rows[i][&quot;FacilityName&quot;].ToString
();
                                objfcl.Add (pft);
                        }
                        this.CloseDBConnection ();
                        return objfcl.ToList ();
                }


My custom class extending from UIPickerViewModel

public class PickerDataModelSource: UIPickerViewModel
        {
                public PickerDataModelSource ()
                {
                }

                public PickerDataModelSource (List&lt;PickerFacilityTemplate> 
lst)
                {
                        this.Items=lst;
                }

                public event EventHandler<EventArgs> ValueChanged;

                public List<PickerFacilityTemplate> Items;
                {
                        get
                        {
                                return this._items;
                        }
                        set
                        {
                                this._items=value;
                        }
                }

                List<PickerFacilityTemplate> _items = new 
List<PickerFacilityTemplate>();

                public PickerFacilityTemplate SelectedItem 
                {
                        get 
                        { 
                                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].FacilityName.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 the class file of the screen where I have the pickerview, I have
written,

PickerDataModelSource _pickerSource;

And in the ViewDidLoad method,

this._pickerSource=new PickerDataModelSource(objdbh.FetchFacility())
this.Picker.Model=this._pickerSource;  [Picker being the name of my control]

But this approach is giving several errors. 
Please help me. I am confused.

Look forward to your reply.


--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/Implementing-UIPickerView-with-data-from-Database-tp4655796p4655869.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to