Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cmd.CommandType = CommandType.Text;
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- var table = new UITableView(this.retrieveData.Frame);
- string[] tableItems = new String[] {dr["admin_num"] + ", " + dr["name"]};
- table.Source = new TableSource(tableItems);
- Add (table);
- }
- cmd.CommandType = CommandType.Text;
- dr = cmd.ExecuteReader();
- // you will need a class mydata with Num and Name properties
- List<mydata> data = new List<mydata>();
- while (dr.Read())
- {
- data.Add(new mydata { Num = dr["admin_num"], Name = dr["name"] });
- }
- dr.Close();
- var table = new UITableView(this.retrieveData.Frame);
- table.Source = new TableSource(data);
- Add (table);
- public List<DemoClass> getDemoClassList()
- {
- List<DemoClass> lstDemoClass;
- DemoClass objDemoClass;
- try
- {
- String strCommandText;
- strCommandText = "SELECT * FROM DemoClass ";
- command = new SqliteCommand(strCommandText, connection);
- lstDemoClass = new List<DemoClass>();
- using (var reader = command.ExecuteReader())
- {
- while (reader.Read())
- {
- objDemoClass = new Homes(false);
- objDemoClass.ID = Convert.ToInt32(reader[0]);
- objDemoClass.Name = Convert.ToString(reader[1]);
- lstDemoClass.Add(objDemoClass);
- }
- }
- return lstDemoClass;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- finally
- {
- command.Dispose();
- command = null;
- lstDemoClass = null;
- objDemoClass = null;
- }
- }
- public void BindList()
- {
- List<DemoClass> lstDemoClass = new List<DemoClass>();
- DemoClass hm = new DemoClass();
- lstDemoClass = (List<DemoClass>)hm.getDemoClassList();
- TableViewDataSource tdatasource = new TableViewDataSource(this, lstDemoClass);
- table.Hidden = false;
- table.DataSource = tdatasource;
- table.Delegate = new TableViewDelegate(this, table, lstDemoClass);
- table.ReloadData();
- }
- #region TableDelegate
- public class TableViewDelegate : UITableViewDelegate
- {
- private DemoPageViewController _Controller;
- private List<DemoClass> lst;
- public TableViewDelegate(DemoPageViewController controller ,UITableView tableView, List<DemoClass> tblList)
- {
- try
- {
- this._Controller = controller;
- this.lst = tblList;
- }
- catch(Exception ex)
- {
- }
- }
- public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
- {
- try
- {
- //This loads the activity spinner till the selection code is completed
- _Controller._loadPop = new LoadingOverlay (new System.Drawing.RectangleF(0,0,_Controller.View.Frame.Width,_Controller.View.Frame.Height),"Loading...");
- _Controller.View.Add ( _Controller._loadPop );
- // spin up a new thread to do some long running work using StartNew
- Task.Factory.StartNew (
- // tasks allow you to use the lambda syntax to pass work
- () => {
- InvokeOnMainThread(delegate{
- DemoClass f = lst[indexPath.Row];
- //Add your code here, usually some navigation or showing a popup
- });
- }).ContinueWith(t => InvokeOnMainThread(() => {
- //Hide the activity spinner
- _Controller._loadPop.Hide();
- }));
- }
- catch(Exception ex)
- {
- }
- finally
- {
- }
- }
- }
- #endregion
- #region TableDataSource
- private class TableViewDataSource : UITableViewDataSource
- {
- static NSString kCellIdentifier = new NSString("MyIdentifier");
- private List<DemoClass> lst;
- private DemoPageViewController controller;
- public TableViewDataSource (DemoPageViewController controller ,List<DemoClass> tblLst)
- {
- this.controller = controller;
- this.lst = tblLst;
- }
- public override int NumberOfSections (UITableView tableView)
- {
- return 1;
- }
- public override int RowsInSection (UITableView tableView, int section)
- {
- return lst.Count;
- }
- // Override to support conditional editing of the table view.
- public override bool CanEditRow (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
- {
- // Return false if you do not want the specified item to be editable.
- return false;
- }
- public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
- {
- try
- {
- UITableViewCell cell = tableView.DequeueReusableCell (kCellIdentifier);
- if (cell == null)
- {
- cell = new UITableViewCell (UITableViewCellStyle.Subtitle, kCellIdentifier);
- cell.Tag = Environment.TickCount;
- }
- DemoClass objDemo = lst[indexPath.Row];
- cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
- cell.ImageView.Image = UIImage.FromFile("Images/CameraImg.png");
- cell.DetailTextLabel.Text = "Show some detail: " + objDemo.DemoDescription.ToString();
- cell.TextLabel.Text = "Some Title: " + objDemo.DemoTitle.ToString();
- return cell;
- }
- catch(Exception ex)
- {
- return null;
- }
- finally
- {
- }
- }
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement