Well I have played around with the code a bit and here is what I have come up
with. I have created three classes, BasicTableViewItem,
BasicTableViewItemGroup, BasicTableViewSource and ClientAssessment. The last
class contains the properties that I want to show from the fetched dataset.
Here are the code blocks for the classes respectively.
BasicTableViewItem
_________________
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using Mono.Data.Sqlite;
namespace ASTONAPP
{
public class BasicTableViewItem
{
public BasicTableViewItem ()
{
}
public string ProjectName{get; set;}
public int ClientID{get; set;}
public int ProjectID{get; set;}
public int FacilityID{get; set;}
}
}
BasicTableViewItemGroup
_______________________
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using Mono.Data.Sqlite;
namespace ASTONAPP
{
public class BasicTableViewItemGroup
{
public BasicTableViewItemGroup (List<ClientAssessment> lst)
{
}
public string Name{get; set;}
public string Footer{get; set;}
public List<BasicTableViewItem> Items
{
get { return this._items; }
set { this._items = value; }
}
protected List<BasicTableViewItem> _items=new
List<BasicTableViewItem>();
}
}
BasicTableViewSource
____________________
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using Mono.Data.Sqlite;
using ASTONAPP;
namespace ASTONAPP
{
public class BasicTableViewSource:UITableViewSource
{
public BasicTableViewSource ()
{
}
protected List<BasicTableViewItemGroup> _tableItems;
string _cellIdentifier = "BasicTableViewCell";
public BasicTableViewSource (List<BasicTableViewItemGroup>
items)
{
this._tableItems = items;
}
public override int NumberOfSections (UITableView tableView)
{
return this._tableItems.Count;
}
public override int RowsInSection (UITableView tableview, int
section)
{
return this._tableItems[section].Items.Count;
}
public override string TitleForHeader (UITableView tableView,
int section)
{
return this._tableItems[section].Name;
}
public override string TitleForFooter (UITableView tableView,
int section)
{
return this._tableItems[section].Footer;
}
public override UITableViewCell GetCell (UITableView tableView,
MonoTouch.Foundation.NSIndexPath indexPath)
{
//---- declare vars
UITableViewCell cell = tableView.DequeueReusableCell
(this._cellIdentifier);
//---- if there are no cells to reuse, create a new one
if (cell == null) {
cell = new UITableViewCell
(UITableViewCellStyle.Subtitle,
this._cellIdentifier);
}
//---- create a shortcut to our item
BasicTableViewItem item = this._tableItems
[indexPath.Section].Items
[indexPath.Row];
cell.TextLabel.Text = item.ProjectName;
cell.DetailTextLabel.Text = item.ProjectID.ToString ();
return cell;
}
}
}
ClientAssessment
_________________
using System;
using System.Collections.Generic;
namespace ASTONAPP
{
public class ClientAssessment
{
public ClientAssessment ()
{
}
public string ProjectName{get; set;}
public int ClientID{get; set;}
public int ProjectID{get; set;}
public int FacilityID{get; set;}
}
}
And here is my function returning List.
_________________________________
public List<ClientAssessment> FetchAssessments ()
{
DataSet ds = new DataSet ();
string sql = "select * from ClientAssessments order by
ProjectName";
this.CreateDBConnection ();
SqliteDataAdapter sda = new SqliteDataAdapter (sql,
sconn);
sda.Fill (ds);
List<ClientAssessment> objca = new
List<ClientAssessment> ();
for (int i=0; i<ds.Tables[0].Rows.Count; i++)
{
ClientAssessment ca = new ClientAssessment ();
ca.ProjectName = ds.Tables [0].Rows [i]
["ProjectName"].ToString ();
ca.ClientID = Convert.ToInt32 (ds.Tables
[0].Rows [i]
["ClientID"].ToString ());
ca.ProjectID = Convert.ToInt32 (ds.Tables
[0].Rows [i]
["ProjectID"].ToString ());
ca.FacilityID = Convert.ToInt32 (ds.Tables
[0].Rows [i]
["FacilityID"].ToString ());
objca.Add (ca);
}
return objca.ToList ();
this.CloseDBConnection();
}
This is what I am doing on the screen where I want to show the fetched data.
________________________________________________________________
BasicTableViewSource _tableViewSource;
public void CreateTableItems ()
{
List<BasicTableViewItemGroup> tableItems = new
List<BasicTableViewItemGroup> ();
BasicTableViewItemGroup tGroup;
tGroup = new BasicTableViewItemGroup
(objdbh.FetchAssessments ());
tableItems.Add (tGroup);
this._tableViewSource = new BasicTableViewSource
(tableItems);
}
and in the view did load method, I am doing this,
this.CreateTableItems ();
this.tblProjects.Source = this._tableViewSource;
But as it stands I am not getting the output. Where am I going wrong? can
you spot some errors in the logic or syntax in my code? Please help me
friends I am really stuck with this. This is my first ever attempt at
working with UITableView. Please help me. I really need your active support.
Many Thanks in advance.
--
View this message in context:
http://monotouch.2284126.n4.nabble.com/UITableView-Scenario-Help-Needed-tp4655680p4655730.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch