C# Xamarin android get Id of listview selection

Jeff Heilman
Jeff Heilman used Ask the Experts™
I've been having trouble returning an Id from my listview to use for deleting a record.  I have a SQLite table that feeds a list adapter.  Here is my class:
public class EOMCountsheet
        [PrimaryKey, AutoIncrement, Column("-id")]
        public int Id { get; set; }
        public string Location { get; set; }
        public int InventoryCount { get; set; }
        public string Part { get; set; }
        public string UserID { get; set; }
        public string UniqueStamp { get; set; }

Open in new window

Here is the Adapter and _listView1.ItemClick:
            string path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "CountSheet.db3");
            var tablelistout = new SQLiteConnection(path);
            var list = tablelistout.Table<EOMCountsheet>().OrderByDescending(t => t.Id).ToList();
            var data = new List<string>();

            foreach (var listing in list)
                data.Add(listing.Id + "  " + listing.Part + " - " + listing.InventoryCount);

            ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(Activity, Android.Resource.Layout.SimpleSelectableListItem, data.ToArray());

            //_listView1.Adapter = listAdapter;

            _listView1 = EOMScanFragment.FindViewById<ListView>(Resource.Id.listView1);

            _listView1.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) =>
                ///GRAB ID HERE AND PASS TO DeleteRow()
                var item = _listView1.SelectedItemId;

            _listView1.Adapter = listAdapter;

Open in new window

Could someone please give a little guidance?  Thanks in advance!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Business Systems Mgr
I ended up parsing the id out of the listview by using GetItemAtPosition.
        private void _listView1_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
            string id =_listView1.GetItemAtPosition(e.Position).ToString().Split(' ')[0];
            int x = 0;
            int.TryParse(id, out x);
            rowID = x;

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial