我查询了我的表以从SQLite数据库中获取数据列表。我可以列出项目,但无法获得所选内容。我试图显示使用DisplayAlert选择的内容。如何获得我选择的东西?下面是我获取数据(tblCaf)的SQLite表。 GetActivity()函数是查询。
[Table("tblCaf")]
public class CAFTable
{
[MaxLength(100)]
public string CAFNo { get; set; }
[MaxLength(100)]
public string TempCAFNo { get; set; }
[MaxLength(100)]
public string EmployeeID { get; set; }
public DateTime CAFDate { get; set; }
[MaxLength(100)]
public string CustomerID { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public string Photo1 { get; set; }
public string Photo2 { get; set; }
public string Photo3 { get; set; }
[MaxLength(1000)]
public string Remarks { get; set; }
[MaxLength(1000)]
public string OtherConcern { get; set; }
}
public void GetActivity()
{
try
{
var db = DependencyService.Get<ISQLiteDB>();
var conn = db.GetConnection();
var getCaf = conn.QueryAsync<CAFTable>("SELECT CAFNo, CAFDate FROM tblCaf WHERE CAFNo != '' ORDER BY CAFDate DESC");
var resultCount = getCaf.Result.Count;
if (resultCount > 0)
{
var result = getCaf.Result;
lstActivityHistory.ItemsSource = result;
}
}
catch (Exception ex)
{
DisplayAlert("Data Error", ex.Message, "Ok");
}
}
private void lstActivityHistory_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var caf = e.SelectedItem as CAFTable;
DisplayAlert("Selected", caf.CustomerID, "ok");
}
答案 0 :(得分:0)
我是这样做的:
var index = (issoLVHistory.ItemsSource as ObservableCollection<TableRow>).IndexOf(e.Item as TableRow);
TableRow
是您的CAFTable
。
希望有帮助。