try changing

var counties = connection.Table<CountyData>();

to the following two lines:

var countiesTable = connection.Table<CountyData>();

var counties = (from i in countiesTable select i).ToList (); // using
System.Linq


basically the object returned from connection.Table<> isn't really a list
you can bind to: you need to perform a query on it that gives you a generic
list that your TableSource expects.

HTH


On Thu, May 17, 2012 at 5:41 AM, Chris_M <[email protected]> wrote:

>
> I'm creating an app that reads data from a pre-created database, one that
> will NOT be modified by the user. This is purely a search and display info
> app. The code below is the main view for the app, which displays a company
> logo, adds a search bar (which will be used essentially to filter the
> displayed data to specific searched-for counties or cities), and upon
> initial display loads and displays the entire list of data (which will be
> about 200 entries, I believe).
>
> My code is based on a couple of the tutorials and gallery projects, but
> chiefly the Data Access gallery example and some advice from the
> inestimable
> Nice Wise. I am also specifically trying to use only the SQLite-Net code to
> work with my database.
>
> I've whittled my way down to just two errors, and after searching and
> reading everything related I can find, I still don't know why they're
> happening or how to fix them. They are both generated by the same line,
> which is marked below by the comment "THIS IS THE PROBLEM LINE RIGHT HERE!"
>
> I apologize in advance for my ignorance and the many other mistakes I have
> no doubt made (and also that this post is kind of long; I thought including
> all the code would be best, though). I'm having a blast learning to combine
> what I've gotten to work from following tutorials and gallery projects, but
> it's a slow, clumsy process sometimes. I wouldn't trade the experience for
> anything, but I have a high tolerance for my own knuckleheadedness.  :-)
>
> Anyway, the two errors I'm getting are:
>
> "The best overloaded match for [the method in question] has some invalid
> arguments." And: "Argument #1 cannot convert 'SQLite.TableQuery<[my
> table]>'
> expression to type 'Systems.Collections.Generic.List<[list with the same
> name as my table]>'
>
> What am I doing wrong, and how can I fix this?
>
> code below===================================================
>
> using System;
> using System.Linq;
> using System.Collections.Generic;
> using MonoTouch.Foundation;
> using MonoTouch.UIKit;
> using MonoTouch.Dialog;
> using System.Drawing;
> using System.Data;
> using System.IO;
> using SQLite;
>
>
> namespace MyDBAccessApp
> {
>        public class HomeNavController : UITableViewController
>        {
>                // declare vars
>                // add these in later when nav button options added
>        //      List<NavItemGroup> navItems = new List<NavItemGroup>();
>        //      NavItemTableSource tableSource;
>
>                protected List<CountyData> counties = new List<CountyData>
> ();
>                protected TableSource tableSource;
>                CountyData county;
>
>                UIImageView imageView;
>                UIImage logoGraphic;
>                UILabel appTitle;
>                UISearchBar searchBar;
>
>                float _TopOfScreen;
>                float _CentScreen;
>                float logoVert;
>                float logoHorz;
>                float appTitleVert;
>                float appTitleHorz;
>                float logoWidth;
>                float logoHeight;
>                float barVert;
>
>                string dbName = "FCResData.sqlite";
>
>                public HomeNavController () //:
> base(UITableViewStyle.Grouped)
>                {
>                }
>
>                class SearchDelegate : UISearchBarDelegate {
>                        public override void SearchButtonClicked
> (UISearchBar searchBar)
>                        {
>                                        searchBar.ResignFirstResponder ();
>                        }
>
>                        public override void CancelButtonClicked
> (UISearchBar searchBar)
>                        {
>                                        searchBar.ResignFirstResponder ();
>                        }
>                }
>
>                public override void ViewWillAppear (bool animated)
>                {
>                        base.ViewWillAppear (animated);
>                        // hide the nav bar when this controller appears
>                        NavigationController.SetNavigationBarHidden (true,
> true);
>                }
>
>                public override void ViewWillDisappear (bool animated)
>                {
>                        base.ViewWillDisappear (animated);
>                        // show the nav bar when other controllers appear
>                        NavigationController.SetNavigationBarHidden (false,
> true);
>                }
>
>                public override void ViewDidLoad ()
>                {
>
>                        logoGraphic = UIImage.FromFile
> ("images/BooksLogo03.png");
>
>                        logoWidth = logoGraphic.Size.Width;
>                        logoHeight = 200; //logoGraphic.Size.Height;
>
>                        _CentScreen = UIScreen.MainScreen.Bounds.Width / 2;
>                        _TopOfScreen = 20;
>                        logoVert = _TopOfScreen;
>                        logoHorz = _CentScreen - (logoWidth / 2);
>
>                        imageView = new UIImageView(new RectangleF(logoHorz,
> logoVert,logoWidth,logoHeight));
>                        imageView.ContentMode =
> UIViewContentMode.ScaleAspectFit;
>                        imageView.Image = logoGraphic;
>
>                        appTitleVert = _TopOfScreen + logoHeight + 5;
>                        appTitleHorz = _CentScreen - 350;
>
>                        appTitle = new UILabel (new RectangleF
> (appTitleHorz,
> appTitleVert,700,60));
>                        appTitle.Text ="Sales Sites for Texas Foreclosures";
>                        appTitle.Font = UIFont.FromName("Arial-BoldMT",
> 32f);
>                        appTitle.TextAlignment = UITextAlignment.Center;
>
>                        barVert = appTitleVert + 60;
>
>                        searchBar = new UISearchBar(new RectangleF(0,
> barVert, View.Bounds.Width,
> 44)){
>                                Delegate = new SearchDelegate (),
>                                ShowsCancelButton = false,
>                        };
>
>                        var connection = new
> SQLiteConnection(GetDBPath(dbName));
>                        var counties = connection.Table<CountyData>();
>
>                      // THIS IS THE PROBLEM LINE RIGHT HERE! The
> tableSource assignment below.
>
>                        tableSource = new TableSource (counties);
>
>                        TableView = new UITableView () {
>                                        Source = tableSource
>                                };
>
>                        connection.Close ();
>
>                        this.Add(searchBar);
>                        this.Add(appTitle);
>                        this.Add(imageView);
>
>
>                }
>
>
>                // The following also from BasicOperations
>
>                protected string GetDBPath (string dbName)
>                {
>                        // get a reference to the documents folder
>                        var documents = Environment.GetFolderPath
> (Environment.SpecialFolder.Personal);
>
>                        // create the db path
>                        string db = Path.Combine (documents, dbName);
>
>                        return db;
>                }
>
>                // A simple data source for our table -- took this from
> BasicOperations
>
>                protected class TableSource : UITableViewSource
>                {
>                        List<CountyData> items;
>
>                        public TableSource (List<CountyData> items) :
> base() { this.items =
> items; }
>
>                        public override int NumberOfSections (UITableView
> tableView) { return 1;
> }
>
>                        public override int RowsInSection (UITableView
> tableview, int section) {
> return this.items.Count; }
>
>                        public override UITableViewCell GetCell
> (UITableView tableView,
> NSIndexPath indexPath)
>                        {
>                                UITableViewCell cell;
>                                cell = tableView.DequeueReusableCell
> ("item");
>                                if(cell == null)
>                                        cell = new
> UITableViewCell(UITableViewCellStyle.Default, "item");
>                                cell.TextLabel.Text =
> this.items[indexPath.Row].FCCounty + "County;
> City: " + this.items[indexPath.Row].CountySeat;
>                                return cell;
>                        }
>
>                }
>
>        }
> }
>
>
>
> --
> View this message in context:
> http://monotouch.2284126.n4.nabble.com/Problem-with-making-code-based-on-database-access-gallery-project-work-tp4641935.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to