我查询了我的表以获取我的SQLite数据库中的数据列表。我可以列出这些项目,但我无法得到我选择的内容。我尝试使用DisplayAlert显示我选择的内容。我怎样才能得到我选择的内容?下面是我获取数据的SQLite表(tblCaf)。 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");
}
我是这样做的:
var index = (issoLVHistory.ItemsSource as ObservableCollection<TableRow>).IndexOf(e.Item as TableRow);
TableRow
是你的CAFTable
。
希望能帮助到你。